Edentity Web Systems
You solve creative. We crack code.
/Header/WhoWeAre.jpg
 

08/04/2009 Run threads and async handlers under the same impersonated identity as the website
Posted by Joel Varty

When you run a background thread or async handler in asp.net, the thread will not run with the same identity specified in the impersonate tag of the web.config.  You can easily get around this by grabbing the identity before the thread starts and either storing it in a variable or passing it to the thread as part of the ParameterizedThreadStart delegate.

Here are some code chunks to copy and paste:

WindowsIdentity appID= System.Security.Principal.WindowsIdentity.GetCurrent()

ParameterizedThreadStart ts = new ParameterizedThreadStart(RunSyncThread)
Thread workerThread = new Thread(ts)
workerThread.Start(appID)

Now, from the thread itself, you only need to take the Identity object and impersonate using it.

WindowsImpersonationContext wi = appID.Impersonate()

 

Your thread will now operate under the proper identity!

more later – joel

« Back to Blog Main Page |

4 Comment(s)

hello, i subscribed because i do believe this is the right place for me. bye :)
hello, thanks for the great quality of your forum, every time i come here, i'm amazed.
This site is very informative. I find it really useful.
New here. Wanted to say hello. Thanks

Leave Comment

Name:
Comment:  
 
Security Check: 
 
 
Edentity Web Systems Inc.
Suite 201
40 Spadina Ave.
Toronto ON
M5V 2H8
Tel:
416.591.2500
Fax:
416.352.5270
Home | Who We Are | What We Do | Clients & Brands | Careers | Contact

Copyright © 2010 Edentity Web Systems Inc. Privacy Policy