One possible solution I found is test if exists the SpecialAuthorizeAttribute (or any derived AuthorizeAttribute) in the CustomAuthorizeAttribute. Not ideal but works.
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes<SpecialAuthorizeAttribute>().Any() || actionContext.ActionDescriptor.GetCustomAttributes<SpecialAuthorizeAttribute>().Any())
return;
base.OnAuthorization(actionContext);
}
}
Member
13 Points
13 Posts
Override authorization filter with another
Aug 07, 2015 09:49 AM|maxbundchen|LINK
I have a global CustomAuthorizeAttribute define in my Web Api project.
However I have a special Controller where I would like to use a SpecialAuthorizeAttribute.
In the Asp.Net vNext there's have a new set of attributes to override the globals, but how I could make it work in the Web Api 2?
Member
13 Points
13 Posts
Re: Override authorization filter with another
Aug 07, 2015 10:14 AM|maxbundchen|LINK
One possible solution I found is test if exists the SpecialAuthorizeAttribute (or any derived AuthorizeAttribute) in the CustomAuthorizeAttribute. Not ideal but works.