简体   繁体   中英

Can I use DirectoryEntry to list sites within IIS Express

I am on Windows XP. We have Windows 2008 Servers. Need to run IIS Express until we get workstations or virtual machines with newer version of local OS for the real IIS 7.X.

Can I use DirectoryEntry to list my Sites and Virtual Directories when I run c# code under IIS Express? I have examples for setting up the Virtual Directories under IIS Express so that I think I have covered. Now I want to list them to ensure they exist.

Anyone know how to do this in C#? Just a small snippet of what I have been trying causes com exceptions...

DirectoryEntry iisServer = new DirectoryEntry("IIS://localhost/W3SVC/1");
DirectoryEntry folderRoot = iisServer.Children.Find("Root", "/");
var children = folderRoot.Children;

you can try something like this

void ListVirtualDirectories(string serverName, int siteId)
{            
       DirectoryEntry iisServer = new DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteId + "/ROOT");

       foreach (DirectoryEntry webDir in iisServer.Children)
       {
           if (webDir.SchemaClassName.Equals("IIsWebVirtualDir"))
               Console.WriteLine("Found virtual directory {0}", webDir.Name);
       }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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