SignalR Hub连接授权错误

时间:2014-07-22 16:31:37

标签: google-chrome signalr signalr-hub

当尝试连接到在同一Web应用程序中运行的SignalR集线器时,我收到401错误(未经授权)。我可以在OnConnected()方法中放置一个断点,看看我正在访问我的集线器。 Google Chrome中出现此错误。在IE中测试,它工作正常。

客户端代码(JS):

    var connection = $.hubConnection();
    proxy = connection.createHubProxy('myHub');
    connection.start();  // error occurs here

服务器代码(C#)

public class MyHub: Hub
{
    public override Task OnConnected()
    {
        return base.OnConnected();  // I hit this breakpoint
    }

    public void AddLogItem()
    {
        Clients.All.logItemReceived("Adding a log item @ " + DateTime.Now);
    }
}

错误:

WebSocket connection to 'ws://localhost:50303/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=gEGkgEb740vzdMSFcFIfNev1d%2BFP0A9tqPaXGRT84RNSZwLDDShUKFd36fdN1Xx1heMZT3d%2BO0EkvRFtkB%2BZIwh39qcekTn94tUPyrMfX1jiIHAdhHwvGVUUJkLHTUnLxvBBPhU1FIZEn0JuLjFHYQ%3D%3D&connectionData=%5B%7B%22name%22%3A%22jcsecurehub%22%7D%5D&tid=6' failed: Error during WebSocket handshake: Unexpected response code: 401 

其他启动代码:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
    }
}

0 个答案:

没有答案