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
発信者に適切なFrom MSDN: Code Access Security for System.DirectoryServicesを提供する必要があると思います

于 2009-07-07T01:49:34.177 に答える