我正在尝试获取Web应用程序的当前应用程序池名称。我在Google上搜索了很多,发现了几种方法,但似乎没有一种对我有用这是我的实现之一:
private static string GetCurrentApplicationPoolId()
{
string virtualDirPath = AppDomain.CurrentDomain.FriendlyName;
virtualDirPath = virtualDirPath.Substring(4);
int index = virtualDirPath.Length + 1;
index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
index = virtualDirPath.LastIndexOf("-", index - 1, index - 1);
virtualDirPath = "IIS://localhost/" + virtualDirPath.Remove(index);
DirectoryEntry virtualDirEntry = new DirectoryEntry(virtualDirPath);
return virtualDirEntry.Properties["AppPoolId"].Value.ToString();
}
我得到一个错误:Unknown error (0x80005000)
控制面板-程序功能-开启-兼容地查找IIS 6并检查所有内容。
如果您有HttpContext
,请使用此:
HttpContext.Current.Request.ServerVariables["APP_POOL_ID"]