如何添加主机头 - Asp.net 3.5,vb.net

时间:2011-04-28 15:36:32

标签: asp.net vb.net header add host

我的网络管理员不合作,并拒绝访问生产服务器。

有没有办法可以用VB以编程方式在代码隐藏中添加主机头?

我尝试将此代码放在母版页的代码隐藏中,但DirectoryEntry为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

有没有人有简单的答案?

0 个答案:

没有答案