【发布时间】:2020-06-08 05:38:01
【问题描述】:
从开箱即用的 cshtml 页面中,您可以使用 User.IsInRole() 检查用户是否在角色内。在我的应用程序中,我使用自定义 IIdentity 用户并实现我自己的 UserStore、UserManager、RoleManager 等。
在我的自定义身份上,我为应用程序等添加自定义声明。
public async Task<ClaimsIdentity> GenerateUserIdentityAsync( UserManager<CustomIdentity, int> manager )
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync( this, DefaultAuthenticationTypes.ApplicationCookie );
// Add custom user claims here
userIdentity.AddClaim( new Claim( CustomClaimTypes.Application, "Application1" ) );
return userIdentity;
}
如何向 User 或 User.Identity 添加其他方法,例如 User.HasApplication("string")
【问题讨论】:
标签: model-view-controller asp.net-identity