Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR Negotiate 404

Tags:

I am using SignalR 2.0. Everything works fine when running locally on my VS 2012. But when I publish the site on IIS, it breaks. The site loads but one of the scripts returns 404 Not Found. The script is something like.

https://example.com/signalr/negotiate?xxx

This path doesn't exist indeed. The correct path should be:

https://example.com/private/signalr/negotiate?xxx

Note the part in bold.

Inside the WebSite (https://example.com/) I have another Application (https://example.com/private/). This one is using SignalR.

This seems like a bug in SignalR since the signalr/hubs path is accessible from my private site.

like image 509
user1594757 Avatar asked Nov 11 '13 16:11

user1594757


People also ask

How many clients can SignalR handle?

IIS on client operating systems has a limit of 10 concurrent connections. SignalR's connections are: Transient and frequently re-established. Not disposed immediately when no longer used.

How long do SignalR connections stay open?

The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command.

Is SignalR scalable?

SignalR messages are broadcasted to all the connected end-clients through the backplane. Typically, SignalR backplane is a relational database which is slow and not scalable to handle extreme messaging load which is core requirement for high traffic real time web applications.

Does SignalR need SSL?

If your SignalR application transmits sensitive information between the client and server, use SSL for the transport.


2 Answers

I had a similar problem. Here is the documentation for configuring the /signalr URL.

However, my solution differed from the docs. Instead of changing the standard app.MapSignalR(), I changed my client code to use /MyApp/signalr. Here is the code where "MyApp" is the virtual directory of my web application.

        var connection = $.hubConnection('/MyApp/signalr', {useDefaultPath: false});         var changesHub = connection.createHubProxy('changesHub');          changesHub.on('userCountChanged', function (count) {             $('#user-count').text(count);         });          connection.start().done(function () {             console.log('Hub has started');             changesHub.invoke('subscribeToChanges', user.id);         }); 

I tried the other way around (change the MapSignalR to the /signalr path) but this did not work and the negotiation was still routed to /MyApp/signalr/negotiate.

like image 177
styfle Avatar answered Sep 21 '22 11:09

styfle


I had the same problem, with an application running in the IIS Default Web Site.
All the Microsoft examples show the hub url with a starting \, and I had copied those examples. But this meant that the signalr routing was from the Default Web Site rather than the application. Removing the leading \ solved it.

So I used endpoints in Startup.cs like:

endpoints.MapHub<MyHub>("myHub"); 

and hub connections in Javascript like:

var connection = new signalR.HubConnectionBuilder().withUrl("myHub").build(); 
like image 24
PeterF Avatar answered Sep 20 '22 11:09

PeterF