【问题标题】:How do I suppress "friendly error messages" in Internet Explorer?如何抑制 Internet Explorer 中的“友好错误消息”?
【发布时间】:2012-07-18 14:44:11
【问题描述】:

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

<!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 显示发送给用户的页面?

编辑 Chrome 开始做同样的事情in 2008。人们要求修复它;但它被标记为不会修复

您可以在答案中使用相同的技巧来修复它。

【问题讨论】:

    标签: internet-explorer


    【解决方案1】:

    解决办法是PADDING。

    知识库文章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 响应正文的字节长度必须小于阈值

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

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

    【讨论】:

    • 人们讨厌 IE 的另一个原因。
    • 为什么要麻烦以内容长度为条件呢?叹息
    • @andrew 原因是大多数网络服务器显示一个非常无用的404 Not Found The requested resource was not found on this server。 IE 试图捕捉这种无用的错误消息,并显示对用户有帮助的内容。 如果响应长于 512 字节,可以肯定地说网站本身正在尝试向用户显示有用的消息:所以它会使用它反而。除了长度之外,我当然想不出更简单的方法来捕捉毫无意义的404 消息。
    • 值得注意的是相应 MSDN 博客的最后一句话:“显然,如果您要阻止显示友好的错误页面,我们强烈建议您提供比默认值;简单地禁用友好的错误消息而不提供更好的消息是不礼貌的。”
    • @RocketHazmat 讽刺的是 Chrome 开始做同样的事情。
    猜你喜欢
    • 2012-10-21
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 2019-08-26
    • 2010-10-14
    • 2015-11-29
    相关资源
    最近更新 更多