Enumerating IIS 5.0 and 6.0 hosted sites
-
I have an IIS 5.0 server hosting about 20 different websites and another IIS 6.0 hosting 3 currently.... I would like to get a list of the web addresses ( host header info in IIS ) for all these sites programmatically. I've seen some sites regarding setting up a website using System.DirectoryServices (here[^] and here[^]) but I haven't found a good way to return a list of all sites currently hosted in IIS. Any links or info would be helpful. I have been unsuccessful in finding info in MSDN... most of the info in MSDN about System.DirectoryServices is in relation to AD rather than IIS. Adam
// TODO: Write code.
-
I have an IIS 5.0 server hosting about 20 different websites and another IIS 6.0 hosting 3 currently.... I would like to get a list of the web addresses ( host header info in IIS ) for all these sites programmatically. I've seen some sites regarding setting up a website using System.DirectoryServices (here[^] and here[^]) but I haven't found a good way to return a list of all sites currently hosted in IIS. Any links or info would be helpful. I have been unsuccessful in finding info in MSDN... most of the info in MSDN about System.DirectoryServices is in relation to AD rather than IIS. Adam
// TODO: Write code.
Hi there, Basically, there are a couple of technologies which you can use to programmatically manage your IIS server, for example: Active Directory Service Interfaces (ADSI), Windows Management Instrumentation (WMI), System.DirectoryServices ..... Depending on the programming language you want to use as well as the current version of the IIS, you will choose an appropriate option. IMO, on the sites provided in your post, they use the System.DirectoryServices simply because this namespace provides an easy way to access the resources of an Active Directory service provider from managed code, and you already know that IIS is one of the current providers beside LDAP, NDS .... For more information, you can see IIS Programmatic Administration SDK [^] The sample code below prints out all virtual directories at root of the IIS server using the System.DirectoryServices:
private void PrintIISVirtualDir()
{
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
IEnumerator enumerator = root.Children.GetEnumerator();
while(enumerator.MoveNext())
{
DirectoryEntry entry = enumerator.Current as DirectoryEntry;
if(entry.SchemaClassName == "IIsWebVirtualDir")
Console.Out.WriteLine("Name: " + entry.Name);
}
}You can take a quick look at the properties/members of each entry if you want to know more about the virtual directory. And here is a hierarchy of the admin objects available on the IIS server which can give you a better look: IIS Admin Object Hierarchy [^], Metabase Structure [^]. For more information