4

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?

4

1 回答 1

5

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

于 2009-02-25T20:56:43.037 回答