我想显示自定义错误页:
<!doctype html>
<html>
<head><title>400 Bad Request</title></head>
<body><h1>400 Bad Request</h1>
The grob must be in the frobber.
</body>
</html>
不幸的是,Internet Explorer会忽略由HTTP服务器发送的响应; 躲在我的网页,并显示自己:
我怎样才能说服Internet Explorer来显示用户发送的页面?
解决的办法是PADDING。
微软指出在知识库文章KB294807 :
HOW TO:关闭Internet Explorer 5.x和6.x的“显示友好HTTP错误信息”功能在服务器端
...如果被发送到客户端的响应小于或等于指定的阈值,这些“友好”的错误消息只显示。 例如,看一个HTTP 500响应的确切文本,内容长度必须大于512个字节。
实现此填充。 要做到这一点,使用VBScript字符串函数返回相同的字符,这比互联网浏览器5 x用来显示友好的错误消息的ErrorThreshold一个更大的字符串。 例如,添加以下行立即是500-100.asp的标签之前:
<% Response.Write String(513, "_") %>
使它更大
所以,我散装高达响应页面:
<!doctype html>
<html>
<head><title>400 Bad Request</title></head>
<body><h1>400 Bad Request</h1>
The grob must be in the frobber.
<!--
512 bytes of padding to suppress Internet Explorer's "Friendly error messages"
From: HOW TO: Turn Off the Internet Explorer 5.x and 6.x "Show Friendly HTTP Error Messages" Feature on the Server Side
http://support.microsoft.com/kb/294807
Several frequently-seen status codes have "friendly" error messages
that Internet Explorer 5.x displays and that effectively mask the
actual text message that the server sends.
However, these \"friendly\" error messages are only displayed if the
response that is sent to the client is less than or equal to a
specified threshold.
For example, to see the exact text of an HTTP 500 response,
the content length must be greater than 512 bytes.
-->
</body>
</html>
问题解决了。
奖金阅读
是什么让IE决定显示友好的错误页面?
答案是,服务器的响应必须满足两个条件:
- 的HTTP状态代码必须是[400,403,404,405,406,408,409,410,500,501,505]
- HTTP响应身体的字节长度必须比阈值更短的
字节长度的阈值存储在子项\ SOFTWARE \微软\的Internet Explorer \ MAIN \ ErrorThresholds下HKEY_LOCAL_MACHINE注册表中。
- [403,405,410]:256个字节
- [400,404,406,408,409,500,501,505]:512个字节
- 否则:512个字节