Why Powershell's New-WebBinding commandlet creates incorrect HostHeader?

时光总嘲笑我的痴心妄想 提交于 2020-01-11 08:17:08

问题


I am trying to add an MSMQ binding for my IIS Web Site, correct binding should look like this:

So I am executing following line in PowerShell:

New-WebBinding -Name "My Site"  -Protocol net.msmq -HostHeader "localhost"

and it creates the following binding:

prefixing it with *:80:, so my MSMQ messages don't get picked up by WCF service. Maybe I am doing it wrong? How to create a binding with Binding Information set to just "localhost" using this PowerShell comandlet?

Commandlet codumentaiton can be found here.


回答1:


Looking at the decompiled code of the cmdlet, looks like it adding the IPAddress and Port information in the binding and there is no workaround to it.

Relevant sections from the code:

private string ipAddress = "*";
...
builder.Append(this.ipAddress);
...
builder.Append(":" + this.sitePort.ToString(CultureInfo.InvariantCulture) + ":");

But you can do what the cmdlet actually does ( below code from cmdlet):

new-itemproperty -path "IIS:\sites\test" -name bindings -value @{protocol="net.msmq"; bindingInformation="localhost"}



回答2:


Give this a try:

New-ItemProperty "IIS:\sites\NameOfYourSite" -name bindings -value @{protocol="net.msmq";bindingInformation="localhost"}


来源:https://stackoverflow.com/questions/9424362/why-powershells-new-webbinding-commandlet-creates-incorrect-hostheader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!