Signalr 信号器上下文。用户在ApplicationOkie中为空

Signalr 信号器上下文。用户在ApplicationOkie中为空,signalr,asp.net-identity,owin,Signalr,Asp.net Identity,Owin,用户在我的中心为空,我不知道为什么 启动: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, AuthenticationMode = AuthenticationMode.Passive,

用户在我的中心为空,我不知道为什么

启动:

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            AuthenticationMode = AuthenticationMode.Passive,
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity =
                    SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(5),
                        regenerateIdentity:
                            (manager, user) =>
                                user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie))
            }
        });
        app.MapSignalR();

        ConfigureWebApi(app);

        app.UseNancy();

CurrentUser方法引发异常,因为Context.User为null。我不确定有什么额外的信息是有益的。我以为我可以从当前的owin上下文中得到这个,但我看不到一种方法来得到这个。我试图创建一个IAuthorizeHubConnection属性,但是我找不到从IRquest对象获取当前owin上下文的方法。我可以做一个新的。

Signal目前无法使用配置为被动模式的身份验证中间件触发按需身份验证(如Web API w/OWIN可以使用其HostAuthenticationFilter/属性)。切换到激活模式,应能正常工作:

app.UseCookieAuthentication(new CookieAuthenticationOptions {
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    AuthenticationMode = AuthenticationMode.Active,
    Provider = new CookieAuthenticationProvider {
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
            validateInterval: TimeSpan.FromMinutes(5),
            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie)) }
});
app.UseCookieAuthentication(新的CookieAuthenticationOptions{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
AuthenticationMode=AuthenticationMode.Active,
Provider=新CookieAuthenticationProvider{
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(
validateInterval:TimeSpan.FromMinutes(5),
regenerateIdentity:(管理器,用户)=>user.GenerateUserIdentityAsync(管理器,DefaultAuthenticationTypes.ApplicationOkie))}
});

Any您确定信号器请求具有身份验证cookie吗?对/signal/negotiate的请求包括身份验证cookie。对/signal/connect的请求没有.Context.request具有cookie。上下文。用户仍然为空。我想你刚刚阻止了一起精神错乱的监护案件。非常感谢。
app.UseCookieAuthentication(new CookieAuthenticationOptions {
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
    AuthenticationMode = AuthenticationMode.Active,
    Provider = new CookieAuthenticationProvider {
        OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
            validateInterval: TimeSpan.FromMinutes(5),
            regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie)) }
});