When you look at the source code (available at http://aspnetwebstack.codeplex.com/ ), you will see that this is not possible using standard filter classes, IAuthorizationFilter implementations are always executed before IActionFilter implementations. This is because action filters will not be executed when authorization filters return a result.
To solve this problem, you can create your own descendant ControllerActionInvoker class and override the InvokeAction method:
public class MyControllerActionInvoker : ControllerActionInvoker { public override bool InvokeAction(ControllerContext controllerContext, string actionName) {
You need to introduce your own class MyControllerActionInvoker in your controllers in the custom class ControllerFactory :
public class MyControllerFactory : DefaultControllerFactory { private readonly MyControllerActionInvoker actionInvoker = new MyControllerActionInvoker();
And, of course, now you need to register your own MyControllerFactory using the MVC framework. You must do this when you also register your routes:
var controllerFactory = new MyControllerFactory(); ControllerBuilder.Current.SetControllerFactory(controllerFactory);
This implementation works fine here.
Carsten schรผtte
source share