简体   繁体   English

为什么 Powershell 的 New-WebBinding commandlet 创建不正确的 HostHeader?

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

I am trying to add an MSMQ binding for my IIS Web Site, correct binding should look like this:我正在尝试为我的 IIS 网站添加一个 MSMQ 绑定,正确的绑定应该如下所示:

在此处输入图片说明

So I am executing following line in PowerShell:所以我在 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.*:80:前缀,因此 WCF 服务不会接收到我的 MSMQ 消息。 Maybe I am doing it wrong?也许我做错了? How to create a binding with Binding Information set to just "localhost" using this PowerShell comandlet?如何使用此 PowerShell comandlet 创建绑定信息仅设置为“localhost”的绑定?

Commandlet codumentaiton can be found here . Commandlet codumentaiton 可以在这里找到。

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.查看cmdlet的反编译代码,看起来它在绑定中添加了IPAddress和Port信息,并且没有解决方法。

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):但是您可以执行 cmdlet 实际执行的操作(下面来自 cmdlet 的代码):

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

试试这个:

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

If your are running PowerShell ( Core ), aka PowerShell >v7.1.x, you will find yourself in trouble because...如果您正在运行 PowerShell ( Core ),又名 PowerShell >v7.1.x,您会发现自己遇到麻烦,因为...

WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session;
please note that all input and output of commands from this module will be deserialized objects.
If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

The IIS provider isn't available via remoting session. IIS 提供程序无法通过远程会话使用。

The easiest trick is to redirect string via pipeline to Windows PowerShell.最简单的技巧是通过管道将字符串重定向到 Windows PowerShell。

"Import-Module WebAdministration;New-ItemProperty -Path `"IIS:\Sites\$($configuration.Website.Name)`" -Name Bindings -value @{protocol = `"net.msmq`"; bindingInformation = `"localhost`" }" | PowerShell

In this example, the website name is read from the configuration JSON.在此示例中,网站名称是从配置 JSON 中读取的。 You can replace it by a hard-coded site name.您可以将其替换为硬编码的站点名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM