
Customizing ASP.NET Core 5.0
By :

ActionFilters
are a little bit like middleware because they can manipulate the input and the output, but are executed immediately on a specific action or on all actions of a specific controller on the MVC layer, whereas middleware works directly on the request object on the hosting layer. ActionFilters
are created to execute code right before or after the action is executed. They are introduced to execute aspects that are not part of the actual action logic: authorization is one example of these aspects. AuthorizeAttribute
is used to allow users or groups to access specific actions or controllers. The AuthorizeAttribute
is an ActionFilter
. It checks whether the logged-on user is authorized. If not, it redirects them to the login page.
Note
If you apply an ActionFilter
globally, it executes on all actions in your application.
The following code sample shows the skeleton of a normal ActionFilter
and an async ActionFilter
:
using Microsoft.AspNetCore...