Every application requires does some kind of Pre and Post-processing logic to sometimes validate or to do custom logic before executing and returning the actual result. ASP.NET Core provides multiple ways to do the same namely Filters, Middlewares, etc...
We can have multiple middlewares, Filters in a typical application to validate or to do custom implementation to every request in the web application.
A filter is one of the ways to validate your session every time a request comes to your application.
There are different kinds of Filter in ASP.Net Core
- Authorization Filter
- Action Filter
- Result Filter
- Exception Filter
Step 2: Register the filter in ConfiguresServices method in Startup.cs file like below
Step 3: Decorate the Filter as an Attribute in the Controller or specific Controller method
If you want to use for all the controllers methods in your application then you register the filter in ConfigureServices method like below and skip Step 3
Hope you have enjoyed the article.