代码如下:
          
 String constIISWebSiteRoot = "IIS://"+serverName+"/W3SVC/"+serverID+"/ROOT";
            DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);       
   
DirectoryEntry newVirDir = root.Children.Add(virtualDirName, "IIsWebVirtualDir");
            newVirDir.Invoke("AppCreate", true);            newVirDir.Properties["Path"][0] = virtualDirDefaultFolder;
            newVirDir.Properties["AccessRead"][0] = true;
            newVirDir.Properties["AccessScript"][0] = true;
            newVirDir.Properties["DefaultDoc"][0] = defaultDoc;
            newVirDir.Properties["AppIsolated"][0] = 2;
            newVirDir.Properties["DontLog"][0] = true;
            newVirDir.Properties["ContentIndexed"][0] = true;
            newVirDir.Properties["AuthFlags"][0] = 1;            newVirDir.CommitChanges();
            root.CommitChanges();            newVirDir.Close();
            newVirDir.Dispose();
            root.Close();
            root.Dispose();我在网站后台增加创建虚拟目录功能,问题是:
该服务器下有多个站点,我如何获取所用站点的serverID,我知道默认站点的是1 ,但当前站点的是多少呢?怎样才能把虚拟目录创建到当前站点下呢?紧急求救

解决方案 »

  1.   

    //列出站点的所有名称
                DirectoryEntry root = new DirectoryEntry(strWeb);
          foreach(DirectoryEntry oEntry in root.Children)
          {
            if(oEntry.SchemaClassName == strSchema)
            {
              //得到站点显示的名字                      
              //this.comboBox1.Items.Add(oEntry.Name + "," + oEntry.Properties["ServerComment"][0] + "-" +  oEntry.Properties["ServerBindings"][0]);
              this.comboBox1.Items.Add(oEntry.Properties["ServerComment"][0]);
              this.comboBox1.SelectedIndex = 0;
            }
          }
      

  2.   

    string strWeb = "IIS://localhost/W3SVC";
    string strSchema = "IIsWebServer";DirectoryEntry root = new DirectoryEntry(strWeb);
    foreach(DirectoryEntry oEntry in root.Children)
    {
            if(oEntry.SchemaClassName == strSchema)
            {
              //得到站点显示的名字                      
              //this.comboBox1.Items.Add(oEntry.Name + "," + oEntry.Properties["ServerComment"][0] + "-" +  oEntry.Properties["ServerBindings"][0]);
              Response.Write(oEntry.Properties["ServerComment"][0]);
     
            }
          }
      

  3.   

    SiteId = oEntry.Name.ToString();