1
votes

I have a custom attribute to authorize users which inherits AuthorizeAttribute. I've registered the attribute in the global filter at start up and that works as expected. But on some actions I want to pass settings arguments to the attribute.

I cant seem to get it to work when using global filters only when decorating each controller/action individually. Is that as designed?

public class AuthorizationActionFilter : AuthorizeAttribute
{
    public bool RequireAdministrator { get; set; }
    public bool RequireSystemUser { get; set; }
}

[AuthorizationActionFilter(RequireSystemUser = true)]
public class SiteInformationController : Controller
{
}

RequireSystemUser property in the attribute is true only when not adding the AuthorizeActionFilter to the global filters. Is there a way to combine global filters and controller/action specific declarations?

1

1 Answers

1
votes

you can use OverrideAuthorization attribute which was introduced in mvc 5.0 and properly works from 5.1:

[OverrideAuthorization]
[AuthorizationActionFilter(RequireSystemUser = true)]
public class SiteInformationController : Controller
{
}