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

发布于 2025-01-08 06:01:42 字数 589 浏览 0 评论 0原文

我正在尝试为我的 IIS 网站添加 MSMQ 绑定,正确的绑定应如下所示:

在此处输入图像描述

所以我正在 PowerShell 中执行以下行:

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

它创建以下绑定:

在此处输入图像描述

为其添加前缀*:80:,因此 WCF 服务不会接收我的 MSMQ 消息。也许我做错了?如何使用此 PowerShell comandlet 创建将绑定信息设置为“localhost”的绑定?

可以在此处找到 Commandlet codumentaiton。

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

enter image description here

So I am executing following line in PowerShell:

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

and it creates the following binding:

enter image description here

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黎歌 2025-01-15 06:01:42

查看 cmdlet 的反编译代码,看起来它在绑定中添加了 IP 地址和端口信息,并且没有解决方法。

代码中的相关部分:

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

但是您可以执行 cmdlet 实际执行的操作(以下来自 cmdlet 的代码):

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

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"}
揽月 2025-01-15 06:01:42

尝试一下:

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

Give this a try:

New-ItemProperty "IIS:\sites\NameOfYourSite" -name bindings -value @{protocol="net.msmq";bindingInformation="localhost"}
壹場煙雨 2025-01-15 06:01:42

如果您正在运行 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.

无法通过远程会话使用 IIS 提供程序。

最简单的技巧是通过管道将字符串重定向到 Windows PowerShell。

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

在此示例中,网站名称是从配置 JSON 中读取的。您可以将其替换为硬编码的站点名称。

If your are running PowerShell (Core), a.k.a PowerShell >v7.1.x, you will find yourself in trouble because...

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.

The easiest trick is to redirect string via pipeline to 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. You can replace it by a hard-coded site name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文