سؤال

I was using SignalR v. 1.0.0 RC2, and it worked fine. When I upgraded to v. 1.0.1 it stopped working. I am now getting a 403 (forbidden) when I am trying to invoke a method on the hub. I did not change any code - I only updated to the newer version of SignalR. It is important to note that I do not have any problems when I run it locally - only when I run it on AppHarbor, and only in the Chrome browser. It works in IE 10 and Firefox 20.

I know that some work has been done in the newer version of SignalR for authorization. Now you can add an Authorize attribute on your hub, or your hub methods. I want to do that, but first I would like it to work without - like it did before.

This is my hub:

using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;

public class ReceptionHub : Hub
{
    public Task Join(string group)
    {
        return Groups.Add(Context.ConnectionId, group);
    }
}

And this is the client site script (I get the group from a data attribute in the markup):

$(function () {
    var receptionHub = $.connection.receptionHub;

    receptionHub.client.updateStatusBar = function (checkedIn, checkedOut, preRegistered)
    {
        $('#quantityCheckedInToday').html(checkedIn);
        $('#quantityCheckedOutToday').html(checkedOut);
        $('#quantityPreRegistered').html(preRegistered);
    };

    $.connection.hub.start().done(function () {
        var group = $("#statusBar").data("group");
        receptionHub.server.join(group);
    });
});

One difference between my local setup and the setup on AppHarbor is that I run the AppHarbor site on HTTPS, but that was not a problem before. Also, there is a loadbalancer infront of the server on AppHarbor.

The request that fails is a POST request to this URL:

/signalr/send?transport=serverSentEvents&connectionToken=5hSSl7wSPrkD51cmPNw-JCrrdxMn2qOgEgmKt5gKrE4jigE4Sxha3gALHREcyDslqb7xjY9fP8rTMpslKuBJzBCIi-q86ZmHt66xhqi2eioAtvQCO03XlcR0Dq9-RW5G0

Any help is much appreciated

هل كانت مفيدة؟

المحلول

I have now tried using SignalR 1.1.2 - and it still did not work in Chrome, but this time it gave a much better error message. It said that CORS was turned off. I tried turning CORS on in the configuration:

var config = new HubConfiguration
    {
        EnableCrossDomain = true
    };

// Register the default hubs route: ~/signalr
RouteTable.Routes.MapHubs(config);

This fixed the problem I was having, and now it works again in Chrome. I am not sure why CORS needs to be turned on to get it working in Chrome... maybe some special AppHarbor setup.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top