3

I am porting over a action filter attribute from .net framework 4.6 to .net core 3.1 . One thing i noticed in .net core ActionFilterAttribute is that it , in .net core ther is no OnActionExecutedAsync Method. Methods in ActionFilterAttribute :-

public virtual void OnActionExecuted(ActionExecutedContext context);
public virtual void OnActionExecuting(ActionExecutingContext context);
public virtual Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next);
public virtual void OnResultExecuted(ResultExecutedContext context);
public virtual void OnResultExecuting(ResultExecutingContext context);
public virtual Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next); 

I have a couple of async methods that need to executed after the execution of the action . What would be the best practice to do this.

1 Answer 1

5

Use OnActionExecutionAsync, where you can invoke the next delegate and then run your own async logic after:

public override async Task OnActionExecutionAsync(
    ActionExecutingContext context, ActionExecutionDelegate next)
{
    var actionExecutedContext = await next();

    // .. Your awaits here.
}

The next delegate returns the ActionExecutedContext.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.