如何在Internet Explorer中禁止“友好错误消息”?

时间:2012-07-18 14:44:12

标签: internet-explorer

我想显示自定义错误页面:

<!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服务器发送的响应;隐藏我的页面并展示自己的页面:

Generic "This webpage cannot be found" IE error message

如何说服Internet Explorer显示用户发送的页面?

1 个答案:

答案 0 :(得分:36)

解决方案是PADDING。

Microsoft在知识库文章KB294807中注意到:

  

如何:关闭服务器端的Internet Explorer 5.x和6.x“显示友好HTTP错误消息”功能

     

...仅当发送到客户端的响应小于或等于指定阈值时,才会显示这些“友好”错误消息。例如,要查看HTTP 500响应的确切文本,内容长度必须大于512字节。

     

实现此填充。为此,请使用VBScript String函数返回相同字符的字符串,这比Internet Explorer 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 Response主体的字节长度必须小于阈值
  •   
     

字节长度阈值存储在子项\ SOFTWARE \ Microsoft \ Internet Explorer \ Main \ ErrorThresholds下的HKEY_LOCAL_MACHINE中的注册表中。

     
      
  • [403,405,410]: 256字节
  •   
  • [400,404,406,408,409,500,501,505]: 512字节
  •   
  • 否则:512字节
  •   
相关问题