列出虚拟目录权限

时间:2012-11-27 15:17:22

标签: c# visual-studio-2008

所以我跑过这个article来列出虚拟目录。这篇文章展示了如何为DirectoryEntry指定用户名和密码。但我仍然拒绝访问Access。

还有一些我不了解权限的东西。有什么想法吗?

class Program
    {
        static void Main(string[] args)
        {
            //http://www.developmentnow.com/blog/2004/12/29/recursively-list-virtual-directories-in-iis-with-c-and-directoryservices/

            // call the function once to kick it off
            WriteVDirs("localhost", 2, "");

        }

        // function that recursively walks through IIS dir & vdirs & lists all the virtual directories
        public static void WriteVDirs(string serverName, int SiteNumber, string path)
        {
            DirectoryEntry de =
              new DirectoryEntry("IIS://" + serverName + "/W3SVC/" +
              SiteNumber.ToString() + "/Root" + path);
            de.Username = "my-machine/administrator";
            de.Password = "admin";
            DirectoryEntries dirs;
            try
            {
                dirs = de.Children;

            foreach (DirectoryEntry d in dirs)
            {
                if (0 == String.Compare(d.SchemaClassName, "IIsWebDirectory"))
                {
                    string fullPath = path + "/" + d.Name;
                    WriteVDirs(serverName, SiteNumber, fullPath);
                }
                else if (0 == String.Compare(d.SchemaClassName, "IIsWebVirtualDir"))
                {
                    string fullPath = path + "/" + d.Name;
                    Console.WriteLine(fullPath + " : " + d.Properties["Path"].Value);
                    WriteVDirs(serverName, SiteNumber, fullPath);
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("ERROR: " + ex.Message);

        }

    }
}

0 个答案:

没有答案