Async OnActionExecuting in ASP.NET Core's ActionFilterAttribute

Asynchronous filters work a bit differently: first execute code that must be executed before the action, call next() for the actual logic, finally add code to be executed after the action.

public async Task OnActionExecutionAsync(ActionExecutingContext context, 
                                         ActionExecutionDelegate next)
{

    // logic before action goes here

    await next(); // the actual action

    // logic after the action goes here
}

The documentation is here: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters#implementation