Page does not appear when sending 500 status code to client

I have a page (general handler) on which I want to return a 500 status code to a client to indicate that something is wrong. I do it like this:

Response.StatusCode = 500; Response.StatusDescription = "Internal Server Error"; 

And at the same time, I am presenting a friendly message telling the user that something went wrong. But instead of forwarding my message, I get a default IIS message saying something like this:

Server 500 error - internal server error. There is a problem with the resource you are looking for and cannot be displayed.

And if I log in to IIS and delete the page with the 500 error, I get this message:

The page cannot be displayed because an internal server error has occurred.

It works in IIS6, but not in IIS7. What to do to make it work in IIS7?

+3
source share
1 answer

You need one more line to get around IIS7 (based on the 500 error code you set):

 Response.TrySkipIisCustomErrors = true; 

Link: HttpResponse.TrySkipIisCustomErrors

+6
source

All Articles