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

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

 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 response code change, but I could not find a specific filter that does this.

What can change the status code of my response and how can I debug all filters working on this request?

+5
source share
2 answers

The problem was found. The culprit is Child Action , which was executed as part of the processing of the parent controller's action. When a parent controller action is executed with a state of 200 plus content, the Child Action , which is executed as part of the parent action, returns NoContent and status 204 . It modifies the response to have a status of 204 plus the content displayed by the main action.

The fix is ​​to make sure that the Child Action only works as a child action and does not change the whole response.

+1
source

This is correct, which means that everything is in order with the system, something is wrong with the data (content).

For example, the Employee table has two records with identifiers 1 and 2. If you update the record, where id = 3, using ef, you will get this error.

What you need to do is make a valid check of your data.

+1
source

Source: https://habr.com/ru/post/1273453/


All Articles