繁体   English   中英

以编程方式获取应用程序池标识

[英]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;

来自论坛.asp.net

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM