Wednesday, 27 February 2013

Asp.net MVC ActionFilter

Action Filters for performing logic either before an action method is called or after its run.

Action Filters are custom attributes that provide a declarative means to add pre-action and post-action behavior to controller action methods.

ActionFilterAttribute is the base class for all the attribute filters. It provides the following methods to execute a specific logic after and before controller action’s execution:- OnActionExecuting(ActionExecutedContext filterContext)
Just before the action method is called
- OnActionExecuted(ActionExecutingContext filterContext):
After the action method is called and before the result is executed (before view render).
- OnResultExecuting(ResultExecutingContext filterContext):
Just before the result is executed (before view render).
- OnResultExecuted(ResultExecutedContext filterContext):
After the result is executed (after the view is rendered).
By overriding any of these methods into a derived class, you can execute your own filtering code.

No comments:

Post a Comment