【发布时间】:2019-09-17 08:52:01
【问题描述】:
我想使用 .net core webAPI 开发动态角色授权,我的结构是用户有一个角色,并且该角色有一些功能或特性可以访问
我的问题是有什么方法可以获取应用授权策略的函数名称
例如,我有以下代码
[Authorize(Roles = "Admin", Policy = "isHasPermission")]
public async Task<IActionResult> GetAllAsync()
{
var users = await _userService.GetAllAsync();
var userDtos = _mapper.Map<IList<UserDto>>(users);
return Ok(DataMessage.Data(new { users = userDtos }));
//return Ok(userDtos);
}
我的政策是这样的
protected override async Task HandleRequirementAsync(
AuthorizationHandlerContext context,
isHasPermissionRequirement requirement)
{
/*
CAN I GET THE FUNCTION NAME "GetAllAsync" HERE!
TO VALIDATE IF IT IS ONE OF USER'S FEATURE
*/
return await Task.CompletedTask;
}
所以我需要在策略中获取函数名称来验证用户的权限,如果可能的话?
【问题讨论】:
标签: asp.net-core-mvc authorization asp.net-core-webapi policy