Page not rendered when sending statuscode 500 to the client

我的未来我决定 提交于 2019-12-10 19:09:00

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/3288797/page-not-rendered-when-sending-statuscode-500-to-the-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!