Retrieving list of Host Headers programmatically?


Forum Admin
Staff member
Jun 2, 2004
Programming Experience
I'd like to fill a drop down of all host headers bound to the current IIS web site. For example, if you go to, there may be other host headers/web sites associated with this very same one. Is it possible, in to retrieve the list of these host headers bound to the IIS web site in use?
Would be nice to be able to modify them as well...would love to hear any info on this one. Good question.

I assume there's some kind of INI file hidden somewhere...kinda like DNS maybe?
Yeah, XML for Windows 2003, but I'm not sure of the permissions of a ASPNET user (IIS_WPG) to retrieve them. Would probably need admin priv's. The other thought would be WMI, but I haven't messed with that in .NET yet and not sure about permissions issues their either.
The way to do it is using ADSI and the System.DirectoryServices namespace. I have a function that lists all websites on a server etc... It should take but a little work to modify it to what you need.

Private Sub LoadSites(ByVal ServerName As String)

Dim oIISAdmin As System.DirectoryServices.DirectoryEntry

Dim oChildDirectory As System.DirectoryServices.DirectoryEntry

Dim oProperties As System.DirectoryServices.DirectoryEntry

oIISAdmin =
New System.DirectoryServices.DirectoryEntry("IIS://" + ServerName + "/W3SVC")


For Each oChildDirectory In oIISAdmin.Children

If IsNumeric(oChildDirectory.Name) Then


End If


If cboSite.Items.Count > 0 Then cboSite.SelectedIndex = 0

End Sub


Latest posts