SignalR Negotiate 404 on Subdomain

2019-07-04 02:34发布

I've created a small MVC SignalR app which I'm having trouble running on my server under a subdomain: http://chat.mydomain.com, which maps to a folder called /chat.

I've also made a console program using SignalR Client which connects and works perfectly, strangely enough.

The error from the MVC app is a 404 from http://chat.mydomain.com/chat/signalr/negotiate?clientProtocol=[...]. I can see why this is happening but have no idea how to fix it. In my generated hubs file, the line

signalR.hub = $.hubConnection("/chat/signalr", { useDefaultPath: false });

is technically correct, but should read $.hubConnection("/signalr", { useDefaultPath: false });

Any ideas on how to alter this? Or should I just use the raw connection API.

Also why does it work properly from the console app?

Thanks in advance.

1条回答
成全新的幸福
2楼-- · 2019-07-04 03:13

You can continue to use the generated hubs file. You just need to modify the hubConnection's url (which stored at $.connection.hub.url) before you start your SignalR connection.

// This is initially set to "/chat/signalr" as specified in the hubs file
$.connection.hub.url = "/signalr";
$.connection.hub.start()...
查看更多
登录 后发表回答