As the question points out i am trying to read route values from it such as the id or other parameters.
I made this base class
public abstract class PermissionAttributeBase : Attribute, IAsyncAuthorizationFilter
{
/// <inheritdoc />
public async Task OnAuthorizationAsync(AuthorizationFilterContext filterContext)
{
if (filterContext.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
if (controllerActionDescriptor.MethodInfo.IsDefined(typeof(AllowAnonymousAttribute)))
return;
if (!await IsAuthorizedAsync(new PermissionContext(filterContext, controllerActionDescriptor)))
filterContext.Result = new ForbidResult();
}
}
protected abstract Task<bool> IsAuthorizedAsync(PermissionContext permissionContext);
}
However i can't seem to find a way to read the values from it. Are the values not available at the point of authorization perhaps?
I have tried many way but even something like this:
var read = permissionContext.FilterContext.ModelState.TryGetValue("id", out var val3);
returns no value at all.
For MVC The parameter values for action are available on the ActionExecutingContext not on ControllerActionDescriptor.
Try ActionExecutingContext.ActionArguments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With