簡體   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