0
使用ServerManager的類是有可能從一個應用程序的物理路徑獲取應用程序池的名字嗎?停止的應用程序池 - ServerManager的C#
using (var manager = new ServerManager())
//using (var manager = ServerManager.OpenRemote("xxx")) //Uncomment this line to enable remote debugging, comment out line 1821, update Server Name value
{
//Get Site using Website ID
var site = manager.Sites.SingleOrDefault(m => m.Id == webSiteID);
if (site != null)
{
//foreach (Application app in site.Applications)
//{
bld.AppendLine("1. Stopping App Pool for: " + site.Name);
//Get the application pool name
var application = site.Applications.SingleOrDefault(m => m.VirtualDirectories["/"].PhysicalPath == @"D:/inetpub/TestSite1"); //RETURNS NULL
//Get the application binded to the siteName
var application1 = site.Applications.SingleOrDefault(m => m.Path == "/TestSite1"); //RETURN INFO I REQUIRE
var appPoolName = application.ApplicationPoolName;
//var appPoolName = site.Applications.FirstOrDefault().ApplicationPoolName;
var appPool = manager.ApplicationPools[appPoolName];
if (appPool != null)
{
//Check the App Pool State
if (appPool.State == ObjectState.Stopped)
{
//App Pool already stopped
bld.AppendLine("1. App Pool: " + appPool.Name + " already stopped.");
}
else
{
//Stop the App Pool
appPool.Stop();
bld.AppendLine("1. App Pool: " + appPool.Name + " stopped.");
}
}
else
{
bld.AppendLine("1. No App Pool found.");
failFlag = true;
}
//}
}
else
{
bld.AppendLine("1. SiteID: " + webSiteID + " does not exist.");
failFlag = true;
}
}
}
我想,因爲有數百種應用程序使用的物理路徑獲取應用程序,而不是虛擬路徑在我的應用程序數據庫和我:我一直在用下面的代碼測試不能100%,他們都已被配置在IIS中,2路徑將同步,例如D:\ inetpub \ TestSite1和/ TestSite1