5

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?

Mando
  • 11,414
  • 17
  • 86
  • 167
  • Some action/result filter ? – Shyju Nov 17 '17 at 01:31
  • there are a bunch of action filters, I've disabled all of them which were applied globally and at controller/action level - same result, probably some filters are implicitly applied thus I need a way to know all filters participating in the request processing. – Mando Nov 17 '17 at 01:36
  • Could a proxy be between you and modify the status code? At my work he had to add to our apache proxy not to modify the headers. – Max Young Nov 24 '17 at 22:53
  • before the response hit a proxy (or any other intermediate like a fiddler) the status is already changed to 204. I can read corrupted status at Application_EndRequest, while my controller/action returns status 200 with required view/model. – Mando Nov 24 '17 at 23:08
  • @AlexeyStrakh are you using the integrated or legacy pipeline in IIS? – Max Young Nov 24 '17 at 23:18
  • @MaxYoung my application pool process is configured to use `integrated` managed pipeline mode (if it's what you ask) – Mando Nov 24 '17 at 23:21
  • @AlexeyStrakh Is it possible their is a handler in the pipeline that is modify the status code? – Max Young Nov 24 '17 at 23:55
  • @MaxYoung it’s possible, but I’m not sure how to debug all the handlers in the pipeline. How can I narrow down to a specific handler which could give me hard time? – Mando Nov 25 '17 at 00:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159788/discussion-between-max-young-and-alexey-strakh). – Max Young Nov 25 '17 at 00:02

2 Answers2

1

It's correct in a way which means everything is fine with system, something is not right with data (content).

Example, Employee table has two records which has id 1 and 2. If you update record where id = 3 using ef, you will get this error.

What you need to do is.. do a proper validation with your data.

Mike
  • 721
  • 7
  • 13
  • data is correct, data is present, the status returned by a controller is correct (200), the status returned by asp.net application after pipeline execution is not correct (204) – Mando Nov 27 '17 at 05:03
1

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.

Mando
  • 11,414
  • 17
  • 86
  • 167