Best strategy for caching/persisting impersonation tokens between calls?
Programmierus opened this issue · 1 comments
Not really an issue, but more a question :) Was thinking to post on SO first, but decided this is a more appropriate place for such a question...
I have a code running in a loop repeatedly many times, doing some work not requiring impersonation. The result is the IO File operation that I only want to do impersonated. When I do wrap this particular operation in an impersonated call it takes a lot of time since I assume it requests a token with each loop iteration. Putting the whole loop inside the impersonation makes the whole thing look ugly, especially that it's not the only such a scenario in my code... I was hoping to do as less as possible code impersonated since it's a user with kind of elevated privileges.
I was thinking about putting the impersonator to a different dedicated thread/process and keeping it open, waiting for new tasks... Then read about problems with asynchronous tasks and found this relative fresh solution (from links in #32).
Do you have any suggestions for the best strategy in my case? What do u think about asynchronous task scheduler I posted above?
Decided to ask on SO. Closing the issue.