页面在 Firefox 上显示随机符号而不是错误消息

发布于 2024-10-01 08:48:07 字数 1552 浏览 0 评论 0 原文

随机地,在一些项目中,某些页面显示随机符号而不是错误消息。像这样的:

��������I�%&/m�{J�J��t��$@������iG#)�* eVe]f@�흼 ��{���{��;�N'���?\fdl��J�ɞ!���?~|?"��Ey�')=��y6� ���h����Ųi�- �ez���7i�i�L���,�4�̧i���Ίe��Ͼ|uz����:�}�< em>��U{��������΋��~����u.-�����l>F'������Y�l��$k�tF���� ��{�� ��[����'U���|6J�lR��b6��юG�k�^,׏����}<~<�;c �R鱕iV��m�|��� �yDl���tRͮ�|N��>�Ey�裟�k��!z���Ѳ�Y)5 ��G��A�8$D��Ѥ̦oI��]�P �"�/��v[����W��~����m`N�rvk����Mqz3���wV.

它的发生相当随机,似乎是由不同的因素引起的。在这里,它是在文件上传上。

我们在此页面上使用 SharpZipLib,但代码路径不应使用它。

有谁知道为什么会发生这种情况以及如何预防?

编辑:它只发生在 Firefox 上。 IE(8) 正确显示错误消息。

编辑2:它似乎是随机发生的,仅在某些页面/网站上。另一个 IIS 站点上的同一页面运行良好。似乎只能在 IIS7 上执行此操作;我没有关于 IIS6 上的报告,而且我也没有在我的开发机器上遇到过它。

编辑3:看起来只有当页面崩溃时才会发生。

编辑4:好的,所以,它只发生在IIS7上,并且仅当我收到错误500时发生。我认为可能是IIS错误页面有问题。我怎样才能尝试改变它们?

Firebug 给了我这些标头:

响应
缓存控制私有
内容类型text/html;字符集=utf-8
服务器 Microsoft-IIS/7.0
X-AspNet-版本 2.0.50727
X-由 ASP.NET 提供支持
日期 2011 年 4 月 4 日星期一 10:31:24 GMT
内容长度 2284
请求
主持人xxx
用户代理 Mozilla/5.0(Windows;U;Windows NT 6.1;fr;rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16(.NET CLR 3.5.30729;.NET4.0E)
接受text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
接受语言 fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
接受编码 gzip,deflate
接受字符集 ISO-8859-1,utf-8;q=0.7,*;q=0.7
保持活动 115
连接保持活动
推荐人 xxxxx
Cookie xxxxxx

我有什么办法可以说“在这个页面上,我根本不接受 gzip 压缩”?

Randomly, on a few projects, some pages display random symbols instead of an error message. Like this one :

��������I�%&/m�{J�J��t��$@�����iG#)�*��eVe]f@�흼 ��{���{��;�N'���?\fdl��J�ɞ!���?~|?"��Ey�')=��y6����h�����Ųi��- �ez����7i޴i�L���,�4�̧i���Ίe��Ͼ|uz����:�}���U{���������΋��~�ȗu.-�����l>F'�����Y�l��$k�tF������{�� ��[����'U���|6J�lR��b6��юG�k�^,ӏ��߿�}<~<�;c�R鱕iV��m�|��� �yDl���tRͮ�|N��>�Ey�裟�k��!z���Ѳ�Y)5��G��A�8$D��Ѥ̦oI��]�P �"�/��v[����W�~���m`N�rvk���Mqz3���wV�

It happens quite randomly, and seems to be caused by different factors. Here, it's on a file upload.

We use SharpZipLib on this page, but the codepath shouldn't use it.

Does anyone knows why this happens, and how to prevent it ?

EDIT : it only happens on Firefox. IE(8) displays the error message correctly.

EDIT 2 : it seems to happen quite randomly, only on some pages/sites. The same page on another IIS site works well. It seems to do this only on IIS7 ; I have no reports of those on IIS6, and I haven't encountered it on my dev machine.

EDIT 3 : it looks like it happens only when the page crashes.

EDIT 4 : Ok, so, it happens only on IIS7, and only when I get an error 500. I think it might be the IIS error pages that have a problem. How can I try to change them ?

Firebug gives me those headers :

Response
Cache-Control private
Content-Type text/html; charset=utf-8
Server Microsoft-IIS/7.0
X-AspNet-Version 2.0.50727
X-Powered-By ASP.NET
Date Mon, 04 Apr 2011 10:31:24 GMT
Content-Length 2284
Request
Host xxxx
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 ( .NET CLR 3.5.30729; .NET4.0E)
Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Referer xxxxx
Cookie xxxxxx

Is there any way for me to say "on this page, I don't accept gzip compression at all" ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

只等公子 2024-10-08 08:48:07

我没有找到任何真正的解决方案,但我找到了令人满意的解决方法。

请记住,该问题仅在以下情况下才会出现:

  • 该网站是在 IIS7 / Windows Server 2008 上配置的。
  • 显示垃圾符号的页面实际上已崩溃。事实上,产生的“垃圾”是一条未经解压的 gzip 压缩错误消息,或者类似的东西。
  • 对动态或静态内容禁用 gzip 压缩不会改变任何内容

解决方法很简单:拒绝浏览器中的 gzip 压缩内容。在 Firefox 中,如 http://forgetmenotes.blogspot.com/ 所示2009/05/how-to-disable-gzip-compression-in.html

  1. 在 URL 栏中键入 about:config(接受免责声明)
  2. 在 URL 栏下方的过滤器字段中键入编码
  3. 双击“网络”行.http.accept-encoding"
  4. 清空值

在我的网站上,它使用 CSS 做了一些奇怪的事情(之后 StackOverflow 根本没有任何 CSS),但至少它正确地向我显示了错误消息,这使我能够修复错误。

希望它能帮助某人。

I did not find any real solution, but I found a satisfying workaround.

Keep in mind that the problem only arises under those conditions :

  • The website is configured on IIS7 / Windows Server 2008.
  • The page displaying the garbage symbols has, in reality, crashed. The resulting "garbage" is, in fact, an gzip-compressed error message that has not been decompressed, or something like that.
  • Disabling gzip compression on either dynamic or static content does'nt change anything

The workaround is simple : refuse gzip-compressed content in the browser. In Firefox, as seen in http://forgetmenotes.blogspot.com/2009/05/how-to-disable-gzip-compression-in.html :

  1. Type about:config in the URL bar (Accept the disclaimer)
  2. Type encoding in the filter field underneath the URL bar
  3. Doubleclick the line "network.http.accept-encoding"
  4. Empty the value

On my website, it did some weird things with the CSS (and StackOverflow does not have any CSS at all after that), but at least it correctly showed me the error message, which enabled me to fix the bug.

Hopefully it will help someone.

在巴黎塔顶看东京樱花 2024-10-08 08:48:07

对于任何遇到此问题的人来说,另一个解决方法可能是删除应用程序错误的响应过滤器,这将消除编码并通过未压缩的方式发送它。由于这仅适用于错误消息,因此对性能的影响应该很小。

在您的 Global.asax

VB

Sub Application_Error()
    Response.Filter = Nothing
End Sub

C# 中(我认为这是正确的,请参阅下面的博客链接)

protected void Application_Error(object sender, EventArgs e)
{
    Response.Filter = null;
}

所有功劳均归功于 Rick Strahl 和 此博客文章了解解决方法。

注意:我还在这里添加了我自己问题的答案 - IISExpress乱码 HTTP 500 错误消息

Another workaround for anyone stumbling across this could be to remove the response filter on application error, which will get rid of the encoding and send it through uncompressed. Since this is only for error messages the impact on performance should be minimal.

In your Global.asax

VB

Sub Application_Error()
    Response.Filter = Nothing
End Sub

C# (I assume this is right, see blog link below)

protected void Application_Error(object sender, EventArgs e)
{
    Response.Filter = null;
}

All credit to Rick Strahl with this blog post for the workaround.

Note: I also added this an an answer to my own question here - IISExpress garbled HTTP 500 error message

心房敞 2024-10-08 08:48:07

这看起来像 gZip 解码错误。

检查您是否在页面上以某种方式设置了 Content-Length,然后使用 gZip 过滤器。如果是,则从代码中删除内容长度集。

当您发送 Content-Length 然后对其进行压缩并且 iis 无法将标头 Content-Length 更改为新压缩的标头并发送错误的大小时,可能会发生这种情况,然后浏览器会读取错误的大小并无法正确解压缩它。

参考资料:
在负载平衡服务器上加载时,ASP.NET 网站有时会冻结和/或在页面顶部显示奇怪的文本

更新

其他可能的原因是设置了错误的 Response.ContentType ,例如将其设置为文本并发送 gif 图像,或者将其设置为图像并发送文本。

更新 2

也许错误出在内容类型上。设置此标题:

context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-disposition", "attachment; filename=" + cFileNameToShowAndDownload);

This is looks like gZip error decoding.

Check if you set the Content-Length in a way on your pages, and then use gZip filter. If yes then remove the Content-Length set from your code.

This can happend when you send the Content-Length and later you compress it and iis can not change the header Content-Length to the new compressed one, and send the wrong size, then browser is reading the wrong size and fail to decompress it correct.

reference:
ASP.NET site sometimes freezing up and/or showing odd text at top of the page while loading, on load balanced servers

Update

Other possible reason is to set a wronge Response.ContentType, for example to set it as text and you send a gif image, or to set it as image and you send a text.

Update 2

Maybe the error is on the the content type. Set this headers:

context.Response.ContentType = "application/octet-stream";
context.Response.AppendHeader("Content-disposition", "attachment; filename=" + cFileNameToShowAndDownload);
你的笑 2024-10-08 08:48:07

我在 dotnet core 中遇到了类似的问题。 (这个问题现在已经9岁了。不认为这对op有帮助,但也许其他人会发现这有帮助)。

我收到类似的乱码文本,它看起来像 gzip 编码。像所选答案一样在 Firefox 中禁用压缩似乎验证了这一点。仅当尝试使用具有非标准内容的脚本块(kendo 模板)渲染部分视图时,该问题才会出现。这与异常何时发生或不发生无关。

问题归结于配置。我们使用的第三方库破坏了响应。按照 Microsoft 在 https 中概述的方式使用压缩: //learn.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-2.2 修复了问题(我们停止使用第 3 方库)。正如 https://stackoverflow.com/a/54372810/1462295 中提到的,配置压缩和静态时的顺序很重要文件设置。

public void ConfigureServices(IServiceCollection services)
{
    services.AddResponseCompression(options =>
    {
        options.Providers.Add<BrotliCompressionProvider>();
        options.Providers.Add<GzipCompressionProvider>();
    });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    // ordering matters here
    app.UseResponseCompression();
    app.UseStaticFiles();
}

I ran into a similar issue with dotnet core. (This question is closing in on 9 years old right now. Don't think this will help op, but maybe other people will find this helpful).

I was getting similar garbled text, it looked like gzip encoding. Disabling compression in firefox like the selected answer seemed to verify this. The problem only showed up when trying to render a partial view with a script block with non-standard content (kendo template). It wasn't anything related to when an exception was occurring or not.

The problem came down to configuration. We were using a 3rd party library that was breaking the response. Using compression as Microsoft outlines at https://learn.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-2.2 fixed the problem (we stopped using the 3rd party lib). As mentioned on https://stackoverflow.com/a/54372810/1462295 , the ordering matters when configuring the compression and static file setup.

public void ConfigureServices(IServiceCollection services)
{
    services.AddResponseCompression(options =>
    {
        options.Providers.Add<BrotliCompressionProvider>();
        options.Providers.Add<GzipCompressionProvider>();
    });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    // ordering matters here
    app.UseResponseCompression();
    app.UseStaticFiles();
}
寄离 2024-10-08 08:48:07

您还可以使用 ModHeader 扩展在 Chrome(或 Brave)中“修复”此问题。然后只需添加一个名为 Accept-encoding 且值为空的 Request header 并重新加载您的页面:
输入图片此处描述

You can also "fix" this in Chrome (or Brave) with the ModHeader extension. Then just add a Request header with the name Accept-encoding and value of nothing and reload your page:
enter image description here

与酒说心事 2024-10-08 08:48:07

答案有点晚了,但我认为它可以帮助某人。

就我而言,问题在于我在 SQL Server 数据库中使用会话状态。由于我已将 ASPState 数据库移至另一台服务器,因此 web.config 文件中的凭据不是最新的。纠正这一点,解决了问题。

The answer is a little late, but I think it can help someone.

In my case, the problem was that I was using session state in a SQL Server database. Because I had moved the ASPState database to another server, the credentials in the web.config file were not up to date. Correcting this, fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文