C# 如何递归浏览IIS的所有内容?
我使用以下程序递归浏览所有虚拟目录及其子目录和文件:C# 如何递归浏览IIS的所有内容?,c#,security,iis-7,active-directory,iis-6,C#,Security,Iis 7,Active Directory,Iis 6,我使用以下程序递归浏览所有虚拟目录及其子目录和文件: static void Main(string[] args) { string serverName = Environment.MachineName; DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT", @"adminusername", @"password");
static void Main(string[] args)
{
string serverName = Environment.MachineName;
DirectoryEntry dir = new DirectoryEntry("IIS://" + serverName + "/W3SVC/1/ROOT", @"adminusername", @"password");
dir.AuthenticationType = AuthenticationTypes.Secure;
PrintChildren(dir, 0);
}
private static void PrintChildren(DirectoryEntry entry,int level)
{
foreach (DirectoryEntry child in entry.Children)
{
Console.WriteLine("");
Console.WriteLine("|");
for (int i = 0; i < level; i++)
{
Console.Write("----");
}
Console.Write(child.Name);
if (child.Children != null)
{
PrintChildren(child,level + 1);
}
}
}
现在,这个程序确实列出了所有虚拟目录,但只有在少数情况下,它才会列出虚拟目录的子目录。我观察到,这些目录在IIS中启用了匿名访问
如何确保此程序能够浏览IIS的所有内容?是否可以提供/设置其他安全设置?我想您需要为调用方提供正确的DirectoryServicesPermission 从MSDN: