c# GetVirutalDiretory Mapped PhyicalPath

来源:互联网 发布:古风歌词知乎 编辑:程序博客网 时间:2024/04/29 09:45

using System.DirectoryServices;
DiectoryEntry entry=new DirectoryEntry("IIS://Localhost/W3SVC");
foreach(DirectoryEntry entrySite in entry.Children){
    if("IIsWebServer"!=entrySite.SchemeClassName)
     continue;
   foreach(object vSite in entrySite.Properties["ServerBindings"]){
              if(null==vSite)  continue;
             string sSite==vSite.ToString();
            if(sSite.IndexOf("dhz123.studyez.cn",StringComparation.IgnoreCase)>=0){
                               DirectoryEntry  rootEntry=new DirectoryEntry(entrySize.Path+"/ROOT");
                            foreach(Object objPath in rootEntry.Properties["Path"])
                           {
                                      return objPath.ToString()
                            }
           }
  }
}

------------------------------------

 

DirectoryEntry root=new DirectoryEntry("IIS://localhost/W3SVC");
foreach(DirectoryEntry dir in root.Children){
     if(dir.SchemaClassName!="IisWebServer")
             continue;
     PropertyValueCollection pvc=dir.Properties["ServerBindings"];
     string v=string.Empty;
     int kc=pvc.Count;
     for(int i=0;i<kc ;i++){
         v=pvc[i].ToString();
         if(v.indexOf("www.xxx.com")!=-1){
            DirectoryEntry  si=new DirectoryEntry("IIS://localhost/W3SVC/"+dir.Name,"EzPaper");
            return si.Properties["Path"].value.ToString();
         }
     }
}