I am using HostingEnvironment.QueueBackgroundWorkItem to start working in the background of an ASP.Net application based on Scott Hanselman's blog post How to run background tasks in ASP.NET .
I want to run a background job as the current user id. I tried passing WindowsPrincipal and setting Thread.CurrentPrincipal in action, but this did not result in the Action being executed as the current user.
Is this possible, or does HostingEnvironment always mean running as an application pool identifier?
Edit
Not entirely true for my original question, but I also tried passing the value through CallContext.LogicalSetData () and CallContext.LogicalGetData (). On the Get side, the value is always null.
Edit # 2
Also tried this on the queue side:
using (HostingEnvironment.Impersonate(windowsIdentity.Token)) { HostingEnvironment.QueueBackgroundWorkItem(work); }
When the job is actually done, the current WindowsIdentity in action is still the application pool identifier.
Phil sandler
source share