Retrieving list of Host Headers programmatically?

Neal

Forum Admin
Staff member
Joined
Jun 2, 2004
Messages
132
Location
VA
Programming Experience
10+
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 www.mydomain.com, there may be other host headers/web sites associated with this very same www.domain.com one. Is it possible, in asp.net/vb.net 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")

cboSite.Items.Clear()

For Each oChildDirectory In oIISAdmin.Children

If IsNumeric(oChildDirectory.Name) Then

cboSite.Items.Add(oChildDirectory.Properties("ServerComment").Value)

End If

Next

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

End Sub

 
Back
Top