Search code examples
c#.net-coreaction-filter

Why is there no access to context.Result.StatusCode in Action and Result filters?


I'm trying to write an action or result filter that automatically does something if the status code is >= 400. The ActionExecutedContext.Result property looks like it should provide access to the status code: enter image description here

But there is no access to the status code: enter image description here

Is this by design? What's the best way to get the actual status code?


Solution

  • At this point, the IActionResult isn't executed yet so the statuscode may potentially change. This one basically has the answer to this problem: Make a middleware and let that check the status code.