views:

482

answers:

1

I am using impersonation in an application in IIS. I need to write a file to the file system, but don't want to use the impersonated user's credentials in this one case. I need to use the credentials of the app pool.

How do I temporarially elevate a worker process' credentials from impersonated credentials to the app pool's credentials?

+3  A: 

Found the answer after much Googling.

using System.Security.Principal;
WindowsImpersonationContext ctx = 
      WindowsIdentity.Impersonate(System.IntPtr.Zero);
//do stuff in app pool's security context
ctx.Undo();

http://www.mindsharpblogs.com/todd/archive/2005/05/03/467.aspx

Ryan Michela