国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現獲取IIS站點及虛擬目錄信息的方法

2020-01-24 01:26:24
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現獲取IIS站點及虛擬目錄信息的方法。分享給大家供大家參考。具體如下:

using System;using System.DirectoryServices;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{  class Program  {    static void Main(string[] args)    {      DirectoryEntry rootEntry = new DirectoryEntry("IIS://localhost/w3svc");      int siteID = 1;      foreach (DirectoryEntry entry in rootEntry.Children)      {        if (entry.SchemaClassName.Equals("IIsWebServer", StringComparison.OrdinalIgnoreCase))        {          Console.WriteLine("Name: {0}", entry.Name);          Console.WriteLine("Path: {0}", IISWorker.GetWebsitePhysicalPath(entry));          Console.WriteLine("ServerBindings: {0}", entry.Properties["ServerBindings"].Value);          Console.WriteLine();          DirectoryEntry virEntry = new DirectoryEntry(entry.Path + "/ROOT");          foreach (DirectoryEntry entryVirtual in virEntry.Children)          {            if (entryVirtual.SchemaClassName.Equals("IIsWebVirtualDir", StringComparison.OrdinalIgnoreCase))            {              Console.WriteLine("SchemaClassName: {0}", entryVirtual.SchemaClassName);              Console.WriteLine("Name: {0}", entryVirtual.Name);              Console.WriteLine("Path: {0}", entryVirtual.Properties["Path"].Value);              Console.WriteLine();            }          }          int ID = Convert.ToInt32(entry.Name);          if (ID >= siteID)          {            siteID = ID + 1;          }        }      }    }  }  public class IISWorker  {    /// <summary>    /// 得到網站的物理路徑    /// </summary>    /// <param name="rootEntry">網站節點</param>    /// <returns></returns>    public static string GetWebsitePhysicalPath(DirectoryEntry rootEntry)    {      string physicalPath = "";      foreach (DirectoryEntry childEntry in rootEntry.Children)      {        if ((childEntry.SchemaClassName == "IIsWebVirtualDir") && (childEntry.Name.ToLower() == "root"))        {          if (childEntry.Properties["Path"].Value != null)          {            physicalPath = childEntry.Properties["Path"].Value.ToString();          }          else          {            physicalPath = "";          }        }      }      return physicalPath;    }  }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巍山| 正安县| 长治市| 中超| 西藏| 师宗县| 铜陵市| 温泉县| 定南县| 湄潭县| 同德县| 青冈县| 太原市| 阳曲县| 盐源县| 西平县| 东阿县| 朝阳区| 台北市| 桐梓县| 永和县| 沾益县| 南京市| 南宫市| 无棣县| 苏尼特右旗| 怀化市| 新宾| 龙岩市| 郁南县| 新平| 曲松县| 镇坪县| 尖扎县| 利津县| 庄浪县| 玛多县| 和硕县| 行唐县| 政和县| 衡水市|