1

我有以下程序来浏览所有虚拟目录及其子目录和文件(递归):

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 的所有内容?是否可以提供/设置任何其他安全设置?

4

1 回答 1

0

我想你需要给调用者正确的DirectoryServicesPermission
来自 MSDN:System.DirectoryServices 的代码访问安全

于 2009-07-07T01:49:34.177 回答