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.
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.
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.
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.
If your SignalR application transmits sensitive information between the client and server, use SSL for the transport.
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With