Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何递归浏览IIS的所有内容?_C#_Security_Iis 7_Active Directory_Iis 6 - Fatal编程技术网

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: