Get the Application Pool Identity programmatically

百般思念 提交于 2019-11-26 09:41:13

问题


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.


回答1:


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.




回答2:


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;            
}


来源:https://stackoverflow.com/questions/10101162/get-the-application-pool-identity-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!