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 编辑过 |
关键字查询
相关文章
正在查询... |