在IIS中将模拟凭据提升为应用程序池凭据

在IIS中将模拟凭据提升为应用程序池凭据,iis,impersonation,credentials,Iis,Impersonation,Credentials,我正在IIS中的应用程序中使用模拟。我需要将文件写入文件系统,但在这种情况下不希望使用模拟用户的凭据。我需要使用应用程序池的凭据 如何临时将工作进程的凭据从模拟凭据提升到应用程序池的凭据?在大量搜索后找到了答案 using System.Security.Principal; WindowsImpersonationContext ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero); //do stuff in app poo

我正在IIS中的应用程序中使用模拟。我需要将文件写入文件系统,但在这种情况下不希望使用模拟用户的凭据。我需要使用应用程序池的凭据


如何临时将工作进程的凭据从模拟凭据提升到应用程序池的凭据?

在大量搜索后找到了答案

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

能否添加与应用程序池相关的内容的安全上下文