Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 21 January 2015
Keywords : Action Filters, Action Filter, Action Filter MVC, Action Filter ASP .NET MVC , MVC

Action Filters In ASP.NET MVC

Action Filters - Introduction


ASP.NET MVC is a web development framework that is based on Model-View-Controller architectural design pattern.Filters in MVC are one of those feature.Filters are some of the best extension points provided in MVC.Mainly ,ASP.NET MVC provides Action Filters for executing filtering logic either before or after an action method is called. Action Filters are some times custom attributes that provide to add pre-action and post-action behavior to the controller's action methods.


Basically the filters in ASP .NET MVC provides a set features .They are the following :

  1. Custom Authentication
  2. User based or Role based custom Authorization
  3. Error handling or logging
  4. User Activity Logging
  5. Data Caching
  6. Data Compression


Action filter is one type of filter.There are basically five types of filters are available in ASP.NET MVC framework. Then can see what are they :


  • Authentication filters
  • Authorization filters
  • Action filters
  • Result filters
  • Exception filters

Action Filters


When we create Action Filters, it implements an interface called IActionFilterand also we want to declare and implement OnActionExecuting and OnActionexecuted methods.


The following code is usefull for implementing this.





LikeWise MVC also provides the following types of action filters :

  • Authorization filter
  • Action filter
  • Result filter
  • Exception filter



By building Action Filter first we need to create a new project in ASP .NET MVC 4.We can use the Internet or Intranet template.


If a Filters folder does not exist in our project , create one in the project.Also add a class to the Filters folder.Then we can implement it.


In ASP.NET MVC, application of ActionFilter - filter method in the Action method, as shown in the diagram below also its execution process:




Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.