C#取得iis站點(diǎn)子站點(diǎn)和應(yīng)用程序池的信息
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
/// <summary> /// 獲取當(dāng)前IIS站點(diǎn)列表 /// </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站點(diǎn)數(shù)據(jù)封裝 /// </summary> public class IISStationInfo { /// <summary> /// 站點(diǎn)名 /// </summary> public string Name { get; set; } /// <summary> /// 站點(diǎn)指定路徑 /// </summary> public string Path { get; set; } /// <summary> /// 站點(diǎn)標(biāo)識(shí)符 /// </summary> public string ID { get; set; } /// <summary> /// 站點(diǎn)包含的應(yīng)用程序,虛擬路徑等 /// </summary> public List<IISAppInfo> AppList { get; set; } } /// <summary> /// IIS應(yīng)用程序子站點(diǎn)數(shù)據(jù)封裝 /// </summary> public class IISAppInfo { /// <summary> /// 站點(diǎn) /// </summary> public string Name { get; set; } /// <summary> /// 站點(diǎn)的制定路徑 /// </summary> public string Path { get; set; } /// <summary> /// 站點(diǎn)的站點(diǎn)標(biāo)識(shí)符 /// </summary> public string ID { get; set; } /// <summary>
/// 站點(diǎn)的應(yīng)用程序名稱(chēng) /// </summary> public string AppName { get; set; } } 該文章在 2018/9/8 15:46:34 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |