Setting an action to be allowed by only a specific user or role is easy using the [Authorize] attribute. E.g.
[Authorize(Roles = "Administrator")]
public ActionResult Index()
{
...
However, I ran into a problem when I wanted the inverse. Is there a way using MVC framework features to allow all authenticated users except those specified by name or role?
The desired usage would be something akin to:
[DoNotAuthorize(Roles = "RestrictedUser")]
public ActionResult Index()
{
...
One fairly simple solution is to derive from the AuthorizeAttribute class and override its AuthorizeCore method, swapping its true/false logic.