Question

Whats difference between return new HttpStatusCodeResult(500) and cause a real error in the action (like division by zero)?

I'm asking because my customErrors works fine when a error like division by zero ocurred, but if i return new HttpStatusCodeResult(500) the customError dont show my page

Était-ce utile?

La solution

HttpStatusCodeResult is for notifying the browser of the result of an action, using an actual HTTP status code. For example, if the browser tries to load an image that is no longer available, you could send a 404. If the user is attempting to access a resource that requires authentication, you could return a 401.

Errors caused by your code often don't need to inform the browser of an error, but instead need to inform the user, using an error page with a message. This error page though, would (most likely) be sent to the browser with an HTTP status code of 200.

tldr; these are two different types of errors with different meanings, meant for different recipients.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top