views:

53

answers:

1

I have a page (generic handler) on which I want to return the status code 500 to the 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 render a friendly message telling the user that something went wrong. But instead of seing my message, I get the default IIS message saying something like this:

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

And if I go in to IIS and remove the error page for 500, I get this message:

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

It works as intended in IIS6, but not in IIS7. What should I do to get it working in IIS7?

+3  A: 

You need one more line in there to bypass IIS7 taking over (based on the 500 error code you set):

Response.TrySkipIisCustomErrors = true;

Reference: HttpResponse.TrySkipIisCustomErrors

Nick Craver