C#取得iis站點子站點和應用程序池的信息
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
/// <summary> /// 獲取當前IIS站點列表 /// </summary> /// <returns></returns> public static List<IISStationInfo> GetLocalIISStations() { List<IISStationInfo> re = new List<IISStationInfo>(); string entPath = "IIS://localhost/w3svc"; DirectoryEntry ent = new DirectoryEntry(entPath); foreach (DirectoryEntry child in ent.Children) { if (child.SchemaClassName == "IIsWebServer") { IISStationInfo item = new IISStationInfo(); item.ID = child.Name; item.Name = child.Properties["ServerComment"].Value.ToString(); DirectoryEntry root = new DirectoryEntry(entPath + "/" + item.ID + "/ROOT"); item.Path = root.Properties["Path"].Value.ToString(); item.AppList = new List<IISAppInfo>(16); foreach (DirectoryEntry app in root.Children) { if (app.SchemaClassName == "IIsWebVirtualDir") { IISAppInfo appitem = new IISAppInfo(); appitem.Name = app.Name; appitem.ID = app.NativeGuid; appitem.Path = app.Properties["Path"].Value.ToString(); appitem.AppName = app.Properties["AppPoolId"].Value.ToString(); item.AppList.Add(appitem); } } re.Add(item); } } return re; } /// <summary> /// IIS站點數據封裝 /// </summary> public class IISStationInfo { /// <summary> /// 站點名 /// </summary> public string Name { get; set; } /// <summary> /// 站點指定路徑 /// </summary> public string Path { get; set; } /// <summary> /// 站點標識符 /// </summary> public string ID { get; set; } /// <summary> /// 站點包含的應用程序,虛擬路徑等 /// </summary> public List<IISAppInfo> AppList { get; set; } } /// <summary> /// IIS應用程序子站點數據封裝 /// </summary> public class IISAppInfo { /// <summary> /// 站點 /// </summary> public string Name { get; set; } /// <summary> /// 站點的制定路徑 /// </summary> public string Path { get; set; } /// <summary> /// 站點的站點標識符 /// </summary> public string ID { get; set; } /// <summary>
/// 站點的應用程序名稱 /// </summary> public string AppName { get; set; } } 該文章在 2018/9/8 15:46:34 編輯過 |
關鍵字查詢
相關文章
正在查詢... |