2
votes

When attempt is made to access action on controller that does not exist, an HttpException is registered in Application_OnError in global.asax, and Response.StatusCode is set to 200.

However, when Application_EndRequest is reached afterwards, Response.StatusCode is then set to 404.

What module is responsible for this change of StatusCode. Something must have been analyzing the HttpException, although I'm unable to figure out based on what is it determined that it should be changed to 404.

EDIT:

Maybe I wasn't clear. I am not setting response code to 200. It is what I've inspected only, it's been set by something else (presumably MVC).

1
Why do you want to return an OK when a 404 is actually what happens? - Rob
I don't want to return 200. I'm just interested in what is setting it to 404 / which module is hooking up to do it. Is it MVC or something else? - Admir Tuzović

1 Answers

1
votes

You must have forgotten to clear the server error in your Application_Error after setting the response code to 200:

Server.ClearError();

This being said, returning 200 OK status code when an url doesn't exists is very counter intuitive, anti SEO and breaking the HTTP status protocol.