My network admin is being uncooperative and has denied access to the production server.
Is there a way I can programmatically add a host header in the code-behind with VB?
I tried putting this code in the code-behind of the master page but DirectoryEntry is Type 'DirectoryEntry' is not defined.
Private Shared Sub AddHostHeader(ByVal websiteID As System.Nullable(Of Integer), ByVal ipAddress As String, ByVal port As System.Nullable(Of Integer), ByVal hostname As String)
Using directoryEntry = New DirectoryEntry("IIS://localhost/w3svc/" & websiteID.ToString())
Dim bindings = directoryEntry.Properties("ServerBindings")
Dim header = String.Format("{0}:{1}:{2}", ipAddress, port, hostname)
If bindings.Contains(header) Then
Throw New InvalidOperationException("Host Header already exists!")
End If
bindings.Add(header)
directoryEntry.CommitChanges()
End Using
End Sub
Does anyone have the easy answer?