Search code examples
c#asp.netasp.net-mvcaction-filterhttp-status-code-204

ASP.NET controller action returns status code 200 but EndRequest has it as 204 (NoContent)


In my ASP.NET MVC application controller processes a request and returns a specific view with a status code 200. When it gets to Application_EndRequest it's already 204. The response content of my view is correct and is in the response, so only the status code is modified. Here is an example (the status is 204 but the content is there):

HTTP/1.1 204 No Content
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Vary: User-Agent
Access-Control-Allow-Origin: *
Date: Fri, 24 Nov 2017 22:12:17 GMT

It could be an ActionFilter modifying the response code but I wasn't able to find a specific filter which does it.

What could potentially modify the status code of my response and how can I debug all the filters working on a given request?


Solution

  • The issue has been found. The culprit is a Child Action which was executed as part of the parent controller action processing. When the parent controller action is executed with the 200 status plus a content, the Child Action, which is executed as part of the parent action, returns NoContent and status 204. It modifies the response to have the 204 status plus the content rendered by primary action.

    The fix is to make sure that the Child Action works as a child action only and doesn't modify the whole response.