Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WebApi, where should I save data between calls to my ActionFilter?

I have an ActionFilterAttribute which does some stuff both before and after the target action. I would like to save the state of the Executing call for use in the Executed call - but where should I save this data?

I would expect something like this:

public override void OnActionExecuting(HttpActionContext actionContext)
{
    actionContext.SavedState = Precomputation();
}

public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
    var pre = actionExecutedContext.ActionContext.SavedState;
    Postcomputation(pre);
}

but SavedState doesn't actually exist, of course. What should I use instead?

like image 511
ladenedge Avatar asked Feb 20 '23 07:02

ladenedge


1 Answers

Add items to actionContext.Request.Properties as required.

like image 197
Chris Avatar answered Feb 22 '23 02:02

Chris