Action filters are attributes that you can put on Action or entire controller. Action filters modify the way in which Action executing. MVC provides different inbuilt Action Filter as
- OutputCache – caches the output of a controller action for a specified amount of time.
- HandleError – handles errors raised when a controller action executes.
- Authorize – enables you to restrict access to a particular user or role.
You can also create you own Action Filter. For suppose you want to create custom authentication system or log the user activity or going to modify the response content (minify the response contents) etc. In all cases you can create you custom Action Filter.
For create a new custom Filter you need to know different type of Action Filters:
- Authentication filters - Implements the
- Authorization filters – Implements the
- Action filters – Implements the
- Result filters – Implements the
- Exception filters – Implements the
Filters are executed in the order listed above.
The base class of action filters is the
System.Web.Mvc.FilterAttribute. If you want to implement a filter, then you need to create a class that inherits from the FilterAttribute class and implements one or more of the
Posted On: 04-Jan-2016 05:39