Get the Application Pool Identity programmatically

前端 未结 3 2027
自闭症患者
自闭症患者 2020-11-29 06:40

How do I get the identity of an appPool programmatically in C#? I want the application pool user and NOT the user who is currently logged in.

相关标签:
3条回答
  • 2020-11-29 07:03

    Another possibility that seems to work OK for me and does not require installation of the Microsoft.Web.Administration package and its legion dependencies:

    string appPoolUserIdentity = WindowsIdentity.GetCurrent().Name;
    

    From forums.asp.net

    0 讨论(0)
  • 2020-11-29 07:09

    You could use System.Security.Principal.WindowsIdentity.GetCurrent().Name to identify the Identity in which the current application is running. This link provides a nice utility which displays the identity under which the aspx is run.

    0 讨论(0)
  • 2020-11-29 07:13

    You need to make a reference to Microsoft.Web.Administration (in Microsoft.Web.Administration.dll). Microsoft.Web.Administration.dll is located in C:\Windows\System32\inetsrv.

    //Add this to your using statements:
    using Microsoft.Web.Administration;
    
    //You can get the App Pool identity like this:    
    public string GetAppPoolIdentity(string appPoolName)
    {
        var serverManager = new ServerManager();
    
        ApplicationPool appPool = serverManager.ApplicationPools[appPoolName];
        appPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;
        return appPool.ProcessModel.UserName;            
    }
    
    0 讨论(0)
提交回复
热议问题