我要将用户角色添加到报销申请
var claims = new[]
{
new Claim("Email", model.Email),
new Claim(ClaimTypes.NameIdentifier, user.Id),
new Claim(ClaimTypes.Role, _userManger.GetRolesAsync(user).ToString())
};但是这种方法不起作用。如何获取字符串形式的角色名称?
发布于 2021-02-09 20:35:18
像这样的东西可能对你有用,
var roles = await _userMgr.GetRolesAsync(user);
var claims = new List<Claim>();
claims.Add(new Claim("Email", model.Email));
claims.Add(new Claim(ClaimTypes.NameIdentifier, user.Id));
foreach (var role in roles)
{
claims.Add(new Claim(ClaimTypes.Role, role));
}GetRolesAsync(user)返回角色名称(字符串)的列表,该列表可能超过1个。
https://stackoverflow.com/questions/66118995
复制相似问题