InvalidCastException: Невозможно привести объект типа 'Microsoft.AspNetCore.Mvc.RazorPages.PageActionDescriptor' к типу 'Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor'. App.Web.Controllers.RoleManagerController.GetDynamicPermissionActions () в RoleManagerController.cs, строка 273
[HttpGet("{roleName}/permissions", Name = "GetRolePermissions")]
public async Task<IActionResult> RolePermissions(string roleName)
{
var role = await _roleManager.Roles
.Include(x => x.Claims)
.SingleOrDefaultAsync(x => x.Name == roleName);
if (role == null)
{
return NotFound();
}
var dynamicActions = this.GetDynamicPermissionActions();
return View(new RolePermissionViewModel
{
Actions = dynamicActions,
Role = role
});
}
private List<ActionDtoViewModel> GetDynamicPermissionActions()
{
var actions = new List<ActionDtoViewModel>();
var actionDescriptors = _actionDescriptor.ActionDescriptors.Items;
foreach (var actionDescriptor in actionDescriptors)
{
var descriptor = (ControllerActionDescriptor)actionDescriptor;
var hasPermission = descriptor.ControllerTypeInfo.GetCustomAttribute<AuthorizeAttribute>()?
.Policy == ConstantPolicies.DynamicPermission ||
descriptor.MethodInfo.GetCustomAttribute<AuthorizeAttribute>()?
.Policy == ConstantPolicies.DynamicPermission;
if (hasPermission)
{
actions.Add(new ActionDtoViewModel
{
ActionName = descriptor.ActionName,
ControllerName = descriptor.ControllerName,
ActionDisplayName = descriptor.MethodInfo.GetCustomAttribute<DisplayAttribute>()?.Name,
AreaName = descriptor.MethodInfo.GetCustomAttribute<AreaAttribute>()?.RouteValue
});
}
}
return actions;
}