C# 以编程方式获取应用程序池标识
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10101162/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the Application Pool Identity programmatically
提问by p0enkie
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.
如何在 C# 中以编程方式获取 appPool 的标识?我想要应用程序池用户而不是当前登录的用户。
采纳答案by adt
You could use System.Security.Principal.WindowsIdentity.GetCurrent().Nameto identify the Identity in which the current application is running. This linkprovides a nice utility which displays the identity under which the aspx is run.
您可以使用System.Security.Principal.WindowsIdentity.GetCurrent().Name标识当前应用程序正在运行的身份。此链接提供了一个很好的实用程序,它显示了运行 aspx 的身份。
回答by Donal
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.
您需要引用 Microsoft.Web.Administration(在 Microsoft.Web.Administration.dll 中)。Microsoft.Web.Administration.dll 位于 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;
}

