如果用户的安全标记发生变化,我会尝试将用户注销,但SecurityStampValidator
从不检查安全标记
通过使用SecurityStampValidator.cs中的代码,我发现此调用GetUserManager
中的var manager = context.OwinContext.GetUserManager<TManager>();
始终返回null。
我使用Unity进行依赖注入。参见:
public void ConfigureAuth(IAppBuilder app)
{
CookieOptions = new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromHours(24),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromSeconds(20),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager, DefaultAuthenticationTypes.ApplicationCookie))
}
};
app.UseCookieAuthentication(CookieOptions);
}
unity.RegisterType<ApplicationSignInManager>(new HierarchicalLifetimeManager());
unity.RegisterType<ApplicationUserManager>(new HierarchicalLifetimeManager());
unity.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new HierarchicalLifetimeManager());
问题:如何正确注入用户管理器或正确连接OWIN上下文?