我的网络管理员不合作,并拒绝访问生产服务器。
有没有办法可以用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
有没有人有简单的答案?