是否可以获取应用程序 运行 中的应用程序池(事先不知道网站)?
Is it possible to get the application pool an applicaiton is running in (without knowing the website beforehand)?
我是 运行 ASP.NET 应用程序 (.NET Framework 4.6) Windows 服务器上的 IIS 10。
我读过几个示例,您可以在这些示例中获取特定站点的应用程序池。
ServerManager manager = new ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];
foreach (Application app in defaultSite.Applications)
{
Console.WriteLine(
"{0} is assigned to the '{1}' application pool.",
app.Path, app.ApplicationPoolName);
}
但在这些示例中,我必须定义应用程序所在的网站(据我所知)运行。
现在,当我不想在源代码中固定它时(因为它可以更改),我想知道我如何才能获得应用程序 运行 下的哪个应用程序池名称?
分别通过HostingEnvironment.SiteName
and HostingEnvironment.ApplicationVirtualPath
获取当前站点名称和路径
有了它们,可以像
一样从服务器管理器获取所需的信息
using Microsoft.Web.Administration;
using System.Web.Hosting;
//...
var manager = new ServerManager();
var siteName = HostingEnvironment.SiteName;
var site = manager.Sites[siteName];
var applicationPath = HostingEnvironment.ApplicationVirtualPath;
var application = site.Applications[applicationPath];
Console.WriteLine(
"{0} is assigned to the '{1}' application pool.",
application.Path, application.ApplicationPoolName);
var appPoolName = application.ApplicationPoolName;
var applicationPool = manager.ApplicationPools[appPoolName];
我是 运行 ASP.NET 应用程序 (.NET Framework 4.6) Windows 服务器上的 IIS 10。
我读过几个示例,您可以在这些示例中获取特定站点的应用程序池。
ServerManager manager = new ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];
foreach (Application app in defaultSite.Applications)
{
Console.WriteLine(
"{0} is assigned to the '{1}' application pool.",
app.Path, app.ApplicationPoolName);
}
但在这些示例中,我必须定义应用程序所在的网站(据我所知)运行。
现在,当我不想在源代码中固定它时(因为它可以更改),我想知道我如何才能获得应用程序 运行 下的哪个应用程序池名称?
分别通过HostingEnvironment.SiteName
and HostingEnvironment.ApplicationVirtualPath
获取当前站点名称和路径
有了它们,可以像
一样从服务器管理器获取所需的信息using Microsoft.Web.Administration;
using System.Web.Hosting;
//...
var manager = new ServerManager();
var siteName = HostingEnvironment.SiteName;
var site = manager.Sites[siteName];
var applicationPath = HostingEnvironment.ApplicationVirtualPath;
var application = site.Applications[applicationPath];
Console.WriteLine(
"{0} is assigned to the '{1}' application pool.",
application.Path, application.ApplicationPoolName);
var appPoolName = application.ApplicationPoolName;
var applicationPool = manager.ApplicationPools[appPoolName];