Reputation: 24190
ASP.NET MVC: in the ActionFilterAttribute class, what is the difference between OnActionExecuted and OnResultExecuted? When implementing a compression filter, which methods should the compression code be placed in?
Upvotes: 3
Views: 1712
Reputation: 401
In order to implement a custom action filter you need to inherit from ActionFilterAttribute – this is an abstract class that has four methods that you can override:
OnActionExecuting OnActionExecuted OnResultExecuting OnResultExecuted As their names imply a custom logic can be performed before/after an action method is executed and before/after the result is executed. Action filters have an Order property which specifies the order in which the filter is applied when multiple filters are used to decorate an action method.
Upvotes: 0
Reputation: 30152
Someone has something you might find useful - check this out:
http://nraykov.wordpress.com/2009/12/02/asp-net-mvc-custom-compression-action-filter/
OnActionExecuted occurs after the action has executed. I believe this would be when control has left the method. The action result that is returned though is then executed AFTER the action method. A View for example is not processed in the method even though it is returned as "return View();" - it is actually processed after the action method returns.
OnResultExecuted occurs when the return value (IE the actionresult) has been executed.
Upvotes: 3