I am implementing AuthorizationFilterAttribute for the WebApi controller, but I do not have access to the parameters that are passed to the controller:
In MVC4, this works fine:
public class MyMVCController : Controller
{
[CanAccessMyResourceApi]
public MyViewModel Get(int id)
{
}
}
public class CanAccessMyResourceMVCAttribute : CanAccessAttributeBase
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
var param = filterContext.Controller.ValueProvider.GetValue("id")
}
}
But in WebAPI, I think the parameter should be in ActionArguments, but the "param" is empty here:
public class MyWebApiController : ApiController
{
[CanAccessMyResourceWebApi]
public MyViewModel Get(int id)
{
}
}
public class CanAccessMyResourceWebApiAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext filterContext)
{
var param = filterContext.ActionArguments["id"]
}
}
Is the parameter that is passed to the controller elsewhere? (I checked that the controller action gets the Id value correctly when I remove the filter attribute.)
source
share