问题
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:
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()...
来源:https://stackoverflow.com/questions/26879633/signalr-negotiate-404-on-subdomain