日期:2014-05-20  浏览次数:20483 次

如何在当前站点下创建虚拟目录
问题:
    服务器上有10个站点,当我进入任何一个站点的后台时,要求能够自动创建虚拟目录功能,但系统总是默认加到默认站点下,怎样做才能创建到当前站点下呢?我以前的办法是:列出该服务器下的所有站点,增加时可选择,这样是可以的,但是,编辑时,怎样才能让dropdownlist   自动选中当前站点呢?而且当我删除一项对应记录时,要删除除所创建的虚拟目录?

    问题关键点:怎样获取当前站点的serverID呢?
 
    下面是以前的列表代码:
                string   strWeb   =   "IIS://localhost/W3SVC ";
                string   strSchema   =   "IIsWebServer ";

                DirectoryEntry   root   =   new   DirectoryEntry(strWeb);

                foreach   (DirectoryEntry   oEntry   in   root.Children)
                {
                        if   (oEntry.SchemaClassName   ==   strSchema)
                        {
                                //得到站点显示的名字                                            
                                this.SiteList.Items.Add(new   ListItem(oEntry.Properties[ "ServerComment "][0].ToString(),   oEntry.Name));
                                this.SiteList.SelectedIndex   =   0;
                        }
                }

  是孟老大帮写的

    梦老大要是在,帮忙啊,各位高手们,也帮帮吧。。

------解决方案--------------------
通过找站点的物理路径和当前站点的比较即可
------解决方案--------------------
學習
------解决方案--------------------
读取
oEntry.Properties[ "Path "][0]
------解决方案--------------------
/**//// <summary>
/// 获取虚拟目录的物理路径
/// </summary>
/// <param name= "identifier "> 虚拟目录所属网站的标识符 </param>
/// <param name= "name "> 虚拟目录名称 </param>
/// <returns> </returns>
private string GetWebVirtualDirectoryPath(string identifier, string name)
{
//System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(@ "IIS://LocalHost/W3SVC/1/ROOT/EasyIRM3 ");
System.DirectoryServices.DirectoryEntry de = new System.DirectoryServices.DirectoryEntry(@ "IIS://LOCALHOST/W3SVC/1/ROOT/ " + name);
//string path = de.Path.ToString();

string path = (string)de.Properties[ "Path "].Value;

return path;
}

/**//// <summary>
/// 获取网站的标识符
/// </summary>
/// <param name= "portNumber "> 端口号 </param>
/// <returns> </returns>
private string GetWebSiteIdentifier(string portNumber)
{
DirectoryEntry root = new DirectoryEntry( "IIS://LOCALHOST/W3SVC ");
foreach(DirectoryEntry e in root.Children)