![](/img/trans.png)
[英]Asp.net core 2.0 Angular template: add identity and authentication
[英]Add UserClaim with Identity asp.net core
在我的班级中,我将ApplicationRole
和ApplicationUser
称为:
private readonly RoleManager<ApplicationRole> _roleManager;
private readonly UserManager<ApplicationUser> _userManager;
public Guid RoleId { get; set; }
public Guid UserId { get; set; }
public AssignRoleToUserModel(
RoleManager<ApplicationRole> roleManager,
UserManager<ApplicationUser> userManager)
{
_roleManager = roleManager;
_userManager = userManager;
}
我有一种方法可以为用户分配角色,例如:
public async Task<IActionResult> OnPost(RoleToUserModel model)
{
var roleId = model.RoleId.ToString();
var userId = model.UserId.ToString();
var role = await _roleManager.FindByIdAsync(roleId);
var roleName = role.Name;
var user = await _userManager.FindByIdAsync(userId);
await _userManager.AddToRoleAsync(user, roleName);
return RedirectToPage();
}
所以换句话说。 我用这个添加新的寄存器到UserRole
表
await _userManager.AddToRoleAsync(user, roleName);
我的问题是,向UserClaim
表添加新寄存器的方法是什么? 问候
你几乎拥有一切,你只需要一个你要分配给用户的索赔。
await _userManager.AddClaimAsync(user,claim)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.