您的位置:首页 > 其它

如何得到指定虚拟目录名称的实际路径

2010-12-22 15:50 453 查看
由于刚好需要这么一个功能,因此在网上找了很久没有找到一个我想要的。。把所有的查询结果全部整理了下,然后自己修改了下终于得到我想要的结果,特此留个记号。

//返回的是指定虚拟目录的实际路径;

public string GetWebVirtualDirectoryPath(string iisName)
{
string iisPath = null;
try
{
DirectoryEntry _entry = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");//此处现在只能读取到默认的80端口
DirectoryEntries _entries = _entry.Children;
foreach (DirectoryEntry _cen in _entries)
{
if (_cen.Name.ToLower() == iisName.ToLower())
{
DirectoryEntry root = new DirectoryEntry(_cen.Path);
iisPath = root.Properties["Path"].Value.ToString();
}

// string aa = _cen.Properties["Path"].Value.ToString();IIS://localhost/W3SVC/1/Root/bbb

}
}
catch (Exception ex)
{

throw ex;
}
return iisPath;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐