Routing , Action , Filters in MVC Asp.Net : Part 2
- It is the process of directing the http request to a proper controller & to its action.
- It is implemented by System.Web.Routing
Actions
- Action/Action Methods are responsible to execute & generate response.
- Action are the ultimate request destination in MVC application
Filters
- They are custom classes that provide both i.e. pre-action and post-action behaviour to controller action methods.
There are 4 types of filter in Mvc Asp.Net
- Authorization Filter
- Action Filter
- Result Filter
- Exception Filter
Authorization Filter
- It is the filter whose attribute is used to allow or restrict the action to the user depending on its role or rights.
- Attributes are : [Authorize]
- Methods :
- void OnAuthorization(AuthorizationContext filterContext);
Action Filter
- It is used to implement logic before and after controller action executes.
- Attributes : [OutputCache] , [Authorize] , [HandleError] , [RequireHttpsAttribute]
- Method
- void OnActionExecuted(ActionExecutedContext filterContext);
- void OnActionExecuting(ActionExecutingContext filterContext);
Result Filter
- It contains logic that is executed before and after a view result is executed.
- The view result can be modified before you want to render it to the browser.
Exception Filter
- Exception filter are last type in filters,
- It is used to handle error either by controller action or controller action result.
- It can be also used to log error
No comments