SignalR Negotiate 404

前提是你 提交于 2019-12-04 02:53:09

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 issue when web site with signalr is not running as root site. Below solution worked for me. instead of using /signalr, use ../signalr. it will work with any site name folder. no hardcoded name 'MyApp' var connection = $.hubConnection('../signalr', {useDefaultPath: false});

Had the same issue. web sites running as virtual directories of the root site. For some reason prefixing with ../ as in ../signalr didn't work, but ./signalr did.

My sample code:

function initSR() {
    // logs signalr messages
    $.connection.hub.logging = true;

    // Declare a proxy to reference the hub.             
    var chat = $.connection.myHub;
    $.connection.hub.url = "./signalr";
    $.connection.hub.start();
    // Create a function that the hub can call to broadcast messages.
    chat.client.broadcastMessage = function (message) {
        // Process Message, take action upon receipt
        alert(message);
    };
}
Gustavo Armenta

Probably you added MapSignalR() in your Application (https://example.com/private/). If you want it on the root, then do the configuration on your WebSite (https://example.com/)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!