FILTERS IN MVC
FILTERS IN MVC
NET MVC 5
MVC APPLICATION WORKFLOW
CLIENT
ROUTE / ROUTING
CONTROLLER
ACTION METHOD
VIEW
ACTION METHOD
Action method Level: When you use filters in an action method, the
filter will execute only when the associated action method is accessed.
Controller Level: When you use filters in controller, the filter will execute
for all the actions methods defined in the controller.
Application Level: When you use filters in an application, the filter will
execute for all the actions methods and controllers present in the
application.
EXCEPTION FILTERS IN ASP.NET MVC
5
In an ASP.NET MVC application, you can use exception filters to handle
exceptions that the application throws at runtime.
Exception filters are additional exception handling component of MVC
Framework besides the built-in .NET Framework exception handling
mechanism comprising try-catch block.
The MVC Framework provides a built-in exception filter through the
HandleError filter that the HandleErrorAttribute class implements.
Like other filters, you can use the HandleError filter on an action method or a
controller.
Using HandleError we can avoid try catch.
The HandleError filter handles the exceptions that are raised by the controller
actions and other filters applied to the action.