SignalR 2.0 - 404 in the IIS Virtual Directory

I had a problem deploying a very simple MVC5 application with SignalR 2.0.2 signal. Everything works fine in my local development environment when I run it using IIS Express. When I deploy to IIS, my js gets a 404 error trying to connect to SignalR.

In particular, I am deploying an application / virtual directory that runs under my website by default. When I publish directly to the default website, everything works successfully, so IIS is not a problem.

GET http: // myServer / signalr /negotiate?connectionData=%5B%5D&clientProtocol=1.3&_=1395517687175 404 (not found)

I assume 404 is caused by a missing application name. i.e.: myServer / MyApp / signalr / negotiate ...

I searched for a few posts and SignalR documentation with no luck regarding IIS and applications / virtual directories and SignalR. The following are snippets of code in my application.

Thank!

JS:

var connection = $.hubConnection();
var proxy = connection.createHubProxy('TestHub');

connection.start()
.done(function () {
console.log('Now connected, connection ID=' + connection.id + ' using transport=' +   connection.transport.name);
                })
                .fail(function () { console.log('Could not connect'); });

Startup.cs:

 app.MapSignalR();

Update By changing the following JS code, I was able to “fix” the problem. The question is how true is this?

//var connection = $.hubConnection();
var connection = $.hubConnection("/MyApp/signalr", { useDefaultPath: false });
+4
source share
2 answers

Your correction seems reasonable.

{ useDefaultPath: false } just tells SignalR not to add "/ signalr" to the url, so you can also create your connection object like this: var connection = $.hubConnection("/MyApp");

, - JS, /MyApp/signalr/hubs, :

var proxy = $.connection.testHub;

// Make sure you always wire up client methods before calling start
proxy.client.myClientMethod = function () { /* ... */ };

$.connection.hub.start()
    .done(function () { /* ... */ })
    .fail(function () { /* ... */ });

http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-javascript-client#genproxy

+1

, dev, IIS, , root, URL- . , .

var connection = $.hubConnection(document.location.origin + document.location.pathname);
+1

Source: https://habr.com/ru/post/1532999/


All Articles