我想通过我的应用程序回收应用程序池。
以前我将应用程序池名称存储在我的数据库中并使用它来回收。 但过去我们将应用程序从一个应用程序池移动到另一个应用程序池,有时我们忘记更新数据库中的应用程序池名称。
所以我想通过应用程序获取应用程序池名称并将其用于回收。
答案 0 :(得分:19)
@Razon的修改版本答案:)
public static string GetCurrentApplicationPoolName()
{
ServerManager manager = new ServerManager();
string DefaultSiteName = System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName();
Site defaultSite = manager.Sites[DefaultSiteName];
string appVirtualPath = HttpRuntime.AppDomainAppVirtualPath;
string appPoolName = string.Empty;
foreach (Application app in defaultSite.Applications)
{
string appPath = app.Path;
if (appPath == appVirtualPath)
{
appPoolName = app.ApplicationPoolName;
}
}
return appPoolName;
}
答案 1 :(得分:9)
在许多情况下,只需从环境变量中读取应用程序池的名称即可:
var apppool = System.Environment.GetEnvironmentVariable(
"APP_POOL_ID", EnvironmentVariableTarget.Process);
答案 2 :(得分:5)
这可以提供帮助:ApplicationPoolName属性
命名空间:Microsoft.Web.Administration 程序集:Microsoft.Web.Administration(在Microsoft.Web.Administration.dll中)