Question

Here is my problem. I wish I could list all the IIS web site that is hosted locally. And for each I would like to retrieve the site name, the host name ex. ("localhost: 80") and the port number. I can retrieve a lot of information but could not find where is the information on the host name. Thank you very much.

Here my code [c#] :

DirectoryEntry iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");

        iis = new DirectoryEntry("IIS://" + Environment.MachineName + "/w3svc");

        foreach (DirectoryEntry site in iis.Children)
        {

            if (site.SchemaClassName == "IIsWebServer") 
            {
                Console.Out.WriteLine(site.Name);
                //I do not know the name of the property to find the "host"
                Console.Out.WriteLine(site.Host); ???

            }
        }
Was it helpful?

Solution

I think you'll need to parse it out of the ServerBindings property. The format is IP:Port:Hostname - if it's the default website, Hostname should be either blank or *.

There's also SecureBindings, which (since you want port #'s) you'd need to grab as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top