自从做环境管理以来,碰到部署IIS的站点,现梳理下下站点,子站点,也就是站点下的应用,以及程序池的关系,并附上C#代码。
IIS管理器里面有很多站点,也有很多程序池
在ServerManager中站点是Site,以Name属性来标注,应用是Application,以path属性来标注,程序池ApplicationPool以ApplicationPoolName来标注
/// <summary> /// 根据所有程序池 /// </summary> /// <param name="poolName"></param> /// <returns></returns> public static ApplicationPool getAppPool() { ServerManager manager = new ServerManager(); return manager.ApplicationPools; }
/// <summary> /// 获取所有站点 /// </summary> /// <returns></returns> public static SiteCollection GetAllSite() { ServerManager manager = new ServerManager(); SiteCollection sites = manager.Sites; return sites; }
2. 一个站点下可以有很多个应用程序,站点本身就是一个应用,每个应用对应一个程序池
如上图,站点nocompence下有三个应用:
本身(path=/),对应程序池是nocompence
nocompenceapp1(path=/nocompenceapp1),对应程序池是nocompence1
nocompenceapp2(path=/nocompence2),对应程序池是qqq
站点可以启动,停止,重新启动
程序池也可以启动、停止、回收(相当于重启)
所以某个应用出问题了,要看所在站点有没有启动外,还要看其对应的程序池有没有启动
2.添加应用程序池时界面上有个别名,但是在ServerManger里面对应的是path,而物理路径是保存在VirtualDirectories[0].PhysicalPath这里,这也是让我刚开始迷惑的地方
#region 测试站点、子站点、程序池间关系 public static void PrintSiteSubSiteAppPoolRelation(string siteName,string path) { ServerManager manager = new ServerManager(); Console.WriteLine("Print All Site:"); int i = 0; foreach (Site site in manager.Sites) { Console.WriteLine("Site" + i + " : " + site.Name); i++; } Console.WriteLine(""); Console.WriteLine("Print All SubSite and Application in "+siteName+":"); int j = 0; foreach (Application app in manager.Sites[siteName].Applications) { Console.WriteLine("subSite" + j + " in " + siteName + " : " + app.Path); Console.WriteLine("application"+j+" in "+siteName + " : " + app.ApplicationPoolName); j++; } Console.WriteLine("Print select subsite application:"); string name = manager.Sites[siteName].Applications.Where(o => o.Path == path).First().ApplicationPoolName; Console.WriteLine("ApplicationPoolName of "+path+" in "+siteName+" is "+name); } #endregion
以上测试代码运行正常,所以,获取相应站点,子站点(应用程序)对应的程序池代码如下:
/// <summary> /// 根据站点与应用名名获取该程序池 /// </summary> /// <param name="poolName"></param> /// <returns></returns> public static string getAppPoolName(string siteName, string path) { ServerManager manager = new ServerManager(); return manager.Sites[siteName].Applications.Where(o => o.Path == path).First().ApplicationPoolName; }
转载于:https://blog.51cto.com/4453154/1701240