signalR 401错误($ .connection.hub.start())

时间:2017-03-21 16:06:54

标签: asp.net .net signalr

我尝试在我的页面中使用signalR连接到集线器:

            $(function() {
            var rateHubProxy = $.connection.rateHub;
            //...
            $.connection.hub.url = 'http://localhost:8081/signalr';
            $.connection.hub.connectionSlow(function () {
                console.log('We are currently experiencing difficulties with the connection.')
            });
            $.connection.hub.error(function (error) {
                console.log('SignalR error: ' + error)
            });
            $.connection.hub.start()
                .done(function(){ console.log('Now connected, connection ID=' + $.connection.hub.id); })
                .fail(function(){ console.log('Could not Connect!'); });
        });

但我在$.connection.hub.start()中有401。 RateHub具有Authorize属性。 在我的应用程序中启动配置:

public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);

        CookieAuthenticationOptions cookieOptions = new CookieAuthenticationOptions()
        {
            AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
            CookieName = ".AuctionWebAuth",
            AuthenticationMode = AuthenticationMode.Active
        };
        app.UseCookieAuthentication(cookieOptions);
        app.MapSignalR(new HubConfiguration() {
            EnableDetailedErrors = true,
            EnableJSONP = true
        });
        GlobalHost.HubPipeline.RequireAuthentication();
        GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new SignalRUserIdProvider());            
    }

我如何获得授权?

0 个答案:

没有答案