发送状态code 500到客户端网页时不会呈现 [英] Page not rendered when sending statuscode 500 to the client

查看:103
本文介绍了发送状态code 500到客户端网页时不会呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页(通用处理器)上,我想要的状态code 500返回给客户端,以表明什么是错的。我这样做,是这样的:

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";

而在同一时间,我呈现一个友好的信息,告诉出事了用户。
但不是我的seing消息,我得到默认的IIS消息,说是这样的:

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:

中的服务器错误
  500内部服务器错误。
  存在与你正在寻找的资源的一个问题,它不能被显示。

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

如果我去到IIS,并删除了错误页面500,我得到这个消息:

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.

它的工作原理是打算在IIS6,但不是在IIS7。我应该怎么做才能得到它在IIS7工作?

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

推荐答案

您需要有一个更多一行绕过IIS7接管(基于500错误code设置):

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

Response.TrySkipIisCustomErrors = true;

参考:<一href=\"http://msdn.microsoft.com/en-us/library/system.web.htt$p$psponse.tryskipiiscustomerrors.aspx?ppud=4\"相对=nofollow> Htt的presponse.TrySkipIisCustomErrors

这篇关于发送状态code 500到客户端网页时不会呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆