使用impersonate = true时如何在IIS中获取当前应用程序池用户?

Sim*_*mon 8 .net iis windows-authentication

在.net中托管的网站如何获得网站运行的当前用户.即,应用程序池用户不是访问该站点的当前用户.

使用Windows集成和模拟.

<authentication mode="Windows"/>
<identity impersonate="true"/>
Run Code Online (Sandbox Code Playgroud)

Joh*_*ons 18

要在托管代码中恢复为应用池用户,您可以执行以下操作:

using (WindowsIdentity.Impersonate(IntPtr.Zero)) 
{
   //This code executes under app pool user
}
Run Code Online (Sandbox Code Playgroud)