简体   繁体   English

如何递归浏览IIS的所有内容?

[英]How can I recursively browse all content of IIS?

I have the following program to browse all virtual directories and their sub directories and files (recursively): 我有以下程序来浏览所有虚拟目录及其子目录和文件(递归):

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);
                }
            }
        }

Now this program does list all the virtual directories, but only in a few cases does it list the sub-directories of a virtual directories (Such directories I have observed have Anonymous access enabled in IIS). 现在,该程序确实列出了所有虚拟目录,但仅在少数情况下,它列出了虚拟目录的子目录(我观察到的此类目录在IIS中启用了匿名访问)。

How do I ensure that this program is able to browse all content of IIS? 如何确保该程序能够浏览IIS的所有内容? Are there any other security settings that can be provided/set? 可以提供/设置其他安全设置吗?

I guess you need to give the caller the proper DirectoryServicesPermission 我想您需要给调用者适当的DirectoryServicesPermission
From MSDN: Code Access Security for System.DirectoryServices 从MSDN: System.DirectoryServices的代码访问安全性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM