【发布时间】:2019-07-07 05:47:35
【问题描述】:
我正在尝试检索用户所在的所有角色。
这个在我的本地 IIS 上工作正常,因为我是登录的那个,但是当我将 API 放到服务器上时,它检索的不是我的角色。
[Authorize(Roles = "Admin")]
[HttpGet]
public IActionResult Get()
{
WindowsIdentity user = WindowsIdentity.GetCurrent();
var userRoles = from id in user.Groups
select id.Translate(typeof(NTAccount)).Value;
return Ok(userRoles);
}
如果我将 WindowsIdentity 更改为 IIdentity,我会在本地和服务器上获得正确的用户,但我无法访问角色。
IIdentity user = User.Identity;
return Ok(user);
如何检索用户访问 API 的所有角色列表?
【问题讨论】:
标签: asp.net asp.net-core windows-authentication asp.net-core-webapi