Currently I have [Authorize] attributes on all of the methods on my AdminController except for the Logon action.
What’s the cleanest way to invert this, so I don’t have to remember to add the attributes to all methods, but rather add an attribute only to the method(s) that should be available without being logged in?
Would I be better just moving the Logon action to its own controller, and applying the [Authorize] attribute to the AdminController class?
In ASP.NET MVC 3 you could implement a custom global action filter provider:
which could be registered in
Application_Start:Now if you are using some DI container such as NInject for example it supports filter binding syntax meaning that you could configure the kernel to inject the filter dynamically based on the context.
The pros of this approach is that now nomatter what controller or action is being added to your application => it will require authorization.