Filters and Action Filters in MVC
Types of Filters:-
MVC supports the following types of filters:
• Action filters
• Authorization filters
• Result Filters
• Exception filter
Action Filters:-
Action filters are used to implement logic that is executed before or after a controller action is executed.
Authorization Filters:-
It is used to implement authorization and authentication for action filters
Result Filters:-
Result filters contain logic that is executed before or after the view result is executed.
Exception Filters:-
Exception filters are used to handle errors, either caused by controller actions or controller action results, we can also use them to log exception exceptions.
Action Filters in ASP.NET MVC
Introduction
Action filters can be applied to a controller action or controller, with the help of action filters we can change the way, the action or controller is executed.
MVC provides the following action filters
Output Cache:-
An output cache filter caches the output of an action for a specified period of time.
Handle error:-
It handles errors thrown by an action or controller, redirecting the action to a custom error page if an exception occurs.
Authorize:-
Authorize No Use is used to filter authorized users to access resources.
If we try to access this action it will give below error
Leave a Reply
Want to join the discussion?Feel free to contribute!