Home > Articles > .Net Framework Articles > ASP.NET MVC FILTERS

ASP.NET MVC FILTERS

by SARNAM SINGH   on Jun 27, 2016   Category: .Net Framework  | Level: Beginner  |  Views: 337    |  Points: 100   
Like this article? Bookmark and Share:
ASP.NET MVC FILTERS


ASP.NET MVC FILTERS:

sometimes we need to perform some logic either before executing an action method or after action method runs. So filters come into picture to fulfill such kind of the requirements.

 There are different type of filters provided by ASP.NET MVC
1. Authorization Filter: These filters mainly used to make security decision, whether to execute an action method such as authentication or validating properties of request. Authorize, RequireHttps are the example of authorization filters.Authorization filter runs before any other filters.

2. Action Filters: Action filters used to wrap the executin of an action method. These filters implements IActionFilter interface, which consists of two methods OnActionExecuting, runs before action method and OnActionExecuted, runs after action method and can perform additional processing such as providing extra data to action method, inspecting the return value and canceling the execution of action method.

3. Result Filters: These wrap the execution of action result, implements IResultFilter interface, which consist of two method OnResultExecuting which run before action result object executed and OnResultExecuted and can perform some additional logic such modifying HttpResponse. The outputcacheattribute class is an example of result filter.

4. Exception Filters: These filters execute if there is an unhandled exception thrown during the execution of asp.net mvc pipeline. The HandleErrorAttribute is an example of exception filter.



Like this article? Bookmark and Share:

Most viewed Articles

User Comments


No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts