explain details about this topic
Loading
explain details about this topic
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ankit RajputPosted Jun 18, 2024, 6:00 AM
Filters in ASP.NET MVC are attributes that allow you to add pre and post-processing logic to controller action methods. They provide a way to execute code before or after specific stages in the request processing pipeline. Filters help in addressing cross-cutting concerns such as logging, authorization, and error handling without cluttering the action methods with repetitive code.
Types of Filters in ASP.NET MVC:
Authorization Filters:
[Authorize]Action Filters:
[HandleError]Result Filters:
Exception Filters:
[HandleError]Example:
Here’s a simple example of a custom action filter in ASP.NET MVC:
To use this custom action filter, you simply decorate your controller or action method with it:
In this example, the
CustomActionFilterwill log trace messages before and after the execution of theIndexaction method in theHomeController.Vishal YelvePosted Jun 18, 2024, 5:57 AM
Hi,
Do refer below article
https://www.c-sharpcorner.com/article/overview-on-types-of-filters-in-asp-net-mvc-5/
Jaimin ShethiyaPosted Jun 17, 2024, 10:51 AM
Here is the example,
Authorization Filter
Action Filter
Result Filter
Exception Filter
Rajanikant HawaldarPosted Jun 17, 2024, 10:43 AM
https://www.c-sharpcorner.com/article/filters-in-Asp-Net-mvc-5-0-part-twelve/
https://www.c-sharpcorner.com/article/overview-on-types-of-filters-in-asp-net-mvc-5/
VelladuraiPosted Jun 17, 2024, 10:35 AM
can you please reply with example?
Jaimin ShethiyaPosted Jun 17, 2024, 10:34 AM
Hello,
In ASP.NET MVC, a user request is routed to the appropriate controller and action method. However, there may be circumstances where you want to execute some logic before or after an action method executes. ASP.NET MVC provides filters for this purpose.
ASP.NET MVC Filter is a custom class where you can write custom logic to execute before or after an action method executes. Filters can be applied to an action method or controller in a declarative or programmatic way. Declarative means by applying a filter attribute to an action method or controller class and programmatic means by implementing a corresponding interface.
MVC provides different types of filters. The following table list filter types, built-in filters, and interface that must be implemented to create custom filters.
Thanks