我有2点涉及到的问题:如何使用Asp.Net Identity 2将用户添加到角色后使.AspNet.ApplicationCookie无效?
1)我需要添加/删除 使用Asp.Net身份2.一些远程用户角色我试图 使用UpdateSecurityStamp后invalidate.AspNet.ApplicationCookie,但由于没有密码或用户名 已更改,SecurityStamp保持不变。当我使用ApplicationRoleManger 时,我可以看到用户角色已更新,但在User.Identity声明中它们 保持不变。
2)AspNet.ApplicationCookie验证工作是如何进行的,我如何才能 访问它?
我试图用这个代码,但没有效果
What is ASP.NET Identity's IUserSecurityStampStore<TUser> interface?
更新:这是我的cookie认证设置:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromSeconds(0),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
OnApplyRedirect = ctx =>
{
if (!IsApiRequest(ctx.Request))
{
ctx.Response.Redirect(ctx.RedirectUri);
}
}
}
});
我可以看到user.GenerateUserIdentityAsync (经理)仅在登录时才被触发。
很棒!我完全错过了自己。很高兴为你效力! – trailmax 2014-08-28 22:40:05