[英]Programmatically set up user account for custom identity application pool in IIS 7
[英]Get the Application Pool Identity programmatically
如何以编程方式在 C# 中获取 appPool 的标识? 我想要应用程序池用户而不是当前登录的用户。
您可以使用System.Security.Principal.WindowsIdentity.GetCurrent().Name
来识别运行当前应用程序的身份。 此链接提供了一个很好的实用程序,它显示运行 aspx 的身份。
您需要引用 Microsoft.Web.Administration(在 Microsoft.Web.Administration.dll 中)。 Microsoft.Web.Administration.dll 位于 C:\Windows\System32\.netsrv。
//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;
}
另一种可能性似乎对我有用并且不需要安装 Microsoft.Web.Administration package 及其依赖项:
string appPoolUserIdentity = WindowsIdentity.GetCurrent().Name;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.