代码之家  ›  专栏  ›  技术社区  ›  Ryan Michela

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

  •  4
  • Ryan Michela  · 技术社区  · 16 年前

    我正在IIS中的应用程序中使用模拟。我需要将文件写入文件系统,但在本例中不想使用模拟用户的凭据。我需要使用应用程序池的凭据。

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

    1 回复  |  直到 16 年前
        1
  •  5
  •   Ryan Michela    16 年前

    通过谷歌搜索找到了答案。

    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