我正在使用 Asp.NET Identity 2.1.0
,并将User
可以访问的Accounts
列表存储为Claims
。当User
登录时,会生成ClaimsIdentity
:
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add Claims concerning Account
userIdentity.AddClaim(new Claim("AccountList", SerializedListOfAccounts));
return userIdentity;
}
假设管理员撤销了“用户A”对特定账户的访问权限。我如何强制“用户A”重新生成其“ClaimsIdentity”?请记住这不是在“用户A”的上下文中进行的。而且我不想等到cookie过期(自动生成新的“ClaimsIdentity”)。
有可能吗?难道没有一种方法告诉服务器将“用户A”的cookie视为无效并强制重新生成它吗?
我想要这种行为的原因是创建一个自定义的“AuthorizeAttribute”,可以放在我的控制器上,检查“用户”是否具有访问权限,以避免额外的数据库往返。