Security of the web application is very important to ensure valuable information is protected and not accessible to unauthorized user or entity . There are lots of techniques to maintain the security of the application which depends on security type scenario. So in this article we learn in brief about the ASP.NET MVC filters which are useful to maintain the security during the request processing.
Following are the filters provided by ASP.NET MVC to check the business logic and validation before and after executing the action methods or view results .
Don't Forget To
Following are the filters provided by ASP.NET MVC to check the business logic and validation before and after executing the action methods or view results .
- Authorization filters
- Action filters
- Result filters
- Exception filters
Authorization filters
Used to authenticate request before executing the action method to ensure the request is authenticated and genuine. Authorization filter uses IAuthorizationFilter interface in which authorization filter methods are defined.
Authorization filters has following built in filters
Authorization filters has following built in filters
- Authorize
- RequireHttps
Action filters
Action filter useful to take some action before and after executing the action methods, This action filter implements the IActionFilter interface which includes the following methods .
Result filter useful to perform some action before and after executing view result, This action filter implements the IResultFilter interface which includes the following methods .
Exception filters
Exception filter responsible to manage unhanded exceptions which are occurred during the execution of ASP.NET MVC pipeline request . This filter is very useful to capture and log the exception details wherever you wants. This filter implements the IExceptionFilter interface also it has also built in filter named HandleError.
These filter are executed in the following sequence
Action filter useful to take some action before and after executing the action methods, This action filter implements the IActionFilter interface which includes the following methods .
- OnActionExecuting
- OnActionExecuted
Result filter useful to perform some action before and after executing view result, This action filter implements the IResultFilter interface which includes the following methods .
- OnResultExecuting
- OnResultExecuted
Exception filters
Exception filter responsible to manage unhanded exceptions which are occurred during the execution of ASP.NET MVC pipeline request . This filter is very useful to capture and log the exception details wherever you wants. This filter implements the IExceptionFilter interface also it has also built in filter named HandleError.
These filter are executed in the following sequence
- Authorization filters
- Action filters
- Response filters
- Exception filters
- Filters are used to check some business logic before and after executing the action methods or view result.
- Each filter implements the its own interface methods.
- Filters can be applied on Controller level , action method level as well as globally using filterconfig class
- We can apply multiple filters on single controller or action method
- If given ASP.NET MVC filter does not fulfill the our requirement then we can also create the custom filters using FilterAttribute class.
- Usually filters are registered in Global.asax file
Summary
I hope, this article is useful for all the readers. If you have any suggestions, please contact me.
Don't Forget To
- Subscribe my YouTube Chanel Compile Mode
- Subscribe free email alert of compilemode.com
- Like Facebook page .
- Follow on Twitter.
- Share to your friends
Post a Comment