繁体   English   中英

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

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

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

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: System.DirectoryServices的代码访问安全性

暂无
暂无

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

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