在Signalr Hub中获取Context.User.Identity.IsAuthenticated false

时间:2016-02-17 12:41:22

标签: c# asp.net signalr asp.net-identity signalr-hub

在所有api和breeze api控制器中,我获得了身份验证,但我最近添加了Signalr和映射信号器,如下面的代码所示。它始终给用户身份未经过身份验证。我不知道我的问题在哪里也将身份验证模式设置为" Forms"在web.config中,如答案所示。

 app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

            OAuthAuthorizationServerOptions OAuthOptions = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath = new PathString("/Token"),
                Provider = new ApplicationOAuthProvider(),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
                AllowInsecureHttp = true
            };

            //app.UseOAuthBearerTokens(OAuthOptions);
            app.UseOAuthAuthorizationServer(OAuthOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
            app.MapSignalR();

现在在Signalr的OnConnected()方法

public override Task OnConnected()
        {
            string name = Context.User.Identity.Name;//name is ""
            //..IsAuthticated == false also
            _connections.Add(name, Context.ConnectionId);
            CheckSendMessagesToUser(name);

            return base.OnConnected();
        }

0 个答案:

没有答案