列出IIS 6.0 - c#中的虚拟目录
本文关键字:虚拟 IIS 列出 | 更新日期: 2023-09-27 18:08:52
我写了一个Windows应用程序。我的问题是:我在IIS 6.0中列出了虚拟目录,代码如下所示。我必须找到所选虚拟目录的物理路径。另外,DirectoryEntry类有一个名为properties
的属性。但是,我不会用它。最后,我得到以下错误:
The directory cannot report the number of properties
代码: try
{
string serverName = "localhost";
string VirDirSchemaName = "IIsWebVirtualDir";
iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root",VirDirSchemaName);
return folderRoot.Children;
}
catch (Exception e)
{
throw new Exception("Error while retrieving virtual directories.",e);
}
为什么不使用WMI
using System.DirectoryServices;
private DirectoryEntry _iisServer = null;
private DirectoryEntry iisServer
{
get
{
if (_iisServer == null)
{
string path = string.Format("IIS://{0}/W3SVC/1", serverName);
_iisServer = new DirectoryEntry(path);
}
return _iisServer;
}
}
private IDictionary<string, DirectoryEntry> _virtualDirectories = null;
private IDictionary<string, DirectoryEntry> virtualDirectories
{
get
{
if (_virtualDirectories == null)
{
_virtualDirectories = new Dictionary<string, DirectoryEntry>();
DirectoryEntry folderRoot = iisServer.Children.Find("Root", VirDirSchemaName);
foreach (DirectoryEntry virtualDirectory in folderRoot.Children)
{
_virtualDirectories.Add(virtualDirectory.Name, virtualDirectory);
}
}
return _virtualDirectories;
}
}
列出IIS 5、6和7中的所有虚拟目录