C#实现获取IIS站点及虚拟目录信息的方法

2019-12-26 13:26:35于丽
  • /// <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#程序设计有所帮助。