尝试浏览signalr/hubs时出现HTTP 503服务不可用的错误

18

我有一个在VS2012中创建的基于Windows主机的SignalR hub:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR();
    }
}

public static class SignalR
{
    public static void Start()
    {
        const string url = "http://*:8080";
        WebApp.Start<Startup>(url);
    }
}

 public class Broadcaster : Hub
    {

        public void SendDownloadResult(bool result, string device, string description, string connectionId, string task)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext<Broadcaster>();
            context.Clients.Client(connectionId).sendDownloadResult(result, device, description, task);
        }
    }

我已将此Windows服务部署在3台不同的电脑上,其中两台电脑正常工作,但在另一台电脑上,当我尝试浏览http://localhost:8080/signalr/hubs时,出现HTTP 503服务不可用。

在所有3台电脑上执行代码时均未抛出异常。

我已检查了添加/删除Windows功能中的IIS功能,它们都是相同的。

我错过了什么?

3个回答

40

我能够使用以下设置本地复现这个问题:

  1. 使用NetSh.exe或类似的工具保留http://localhost:8080/
  2. 调用WebApp.Start<Startup>("http://*:8080")
  3. 浏览到http://localhost:8080/

发生的情况是,Http.Sys接受传入请求,检查主机标头,并决定有一个保留在localhost:8080上,但意识到没有应用程序正在侦听localhost:8080,只有*:8080。然后Http.Sys返回503。

解决方案:

  1. 尝试使用 WebApp.Start<Startup>("http://+:8080")
  2. 删除Http.Sys / NetSh注册

我该如何“删除 Http.Sys/NetSh 注册”? - Null Reference
3
在管理员提示符下执行“netsh http delete urlacl url=http://localhost:8080/”应该能解决问题。 - halter73
以下是配置 Http.Sys 的文档和工具链接:https://katanaproject.codeplex.com/wikipage?title=Selfhosting&referringTitle=Documentation - Tratcher
https://learn.microsoft.com/en-us/windows/desktop/http/urlprefix-strings - Tratcher

11

我也遇到了同样的问题。我通过更改来解决它。

 const string url = "http://*:8080";

TO

需要进一步的上下文信息和指示,才能提供更准确的翻译。
 const string url = "http://+:8080"; // * replaced by +

1
我意识到,在其中一台电脑上,端口8080正在被使用。
将端口从
const string url = "http://*:8080";

const string url = "http://*:8088";

解决了问题。

当UrlPrefix的主机元素只包含一个加号(+)时,UrlPrefix将匹配其方案、端口和relativeURI元素上下文中所有可能的主机名,并进入强通配符类别。当星号(*)出现在主机元素中时,UrlPrefix将属于弱通配符类别。这种类型的UrlPrefix将匹配与指定方案、端口和relativeURI相关联的任何主机名,只要该主机名尚未被强通配符匹配。 - Mr Heelis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接