Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
Toned down your question, so it wouldn't get closed as offensive. Try to be civil here in the future. – Oded Apr 28 '11 at 15:40
Sure thing buddy. Thanks for looking out for me. :-/ – Jon Apr 28 '11 at 16:03

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.