简体   繁体   English

ASP.net应用程序中的奇怪错误屏幕

[英]Weird Error screen in ASP.net Application

I am working on some ASP.NET Application. 我正在研究一些ASP.NET应用程序。 In case of some breakdown or error, I am getting some weird error screen. 如果出现故障或错误,我会收到一些奇怪的错误屏幕。 The error page shows something like: 错误页面显示如下内容:

��`I�%&/m�{J�J��t��`$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N'���?
\fdl��J�ɞ!���?~|?"��Ey�')=��y6�����h��贮
�:�V�˼n��E:��,m�Wy�����<�ӶJ�e;~|W^�`4�u�A:�f��/>

and so on.... 等等....

The application is currently in test phase so, I have left the error screen visible from web.config. 该应用程序目前处于测试阶段,因此我从web.config中看到了错误屏幕。 Anyone who have faced the same issue, and got the problem and solution for it? 任何遇到过同样问题的人,都会遇到问题和解决方案吗?

Check out whether the ASP.NET application you are working on utilizes some form of automatic GZip compression, your error page is very reminiscent of what Rick Strahl describes here: http://www.west-wind.com/weblog/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats . 看看你正在使用的ASP.NET应用程序是否采用某种形式的自动GZip压缩,你的错误页面让人想起Rick Strahl在这里描述的内容: http//www.west-wind.com/weblog/posts/2011 / May / 02 / ASPNET-GZip-Encoding-Caveats There is also a solution in that blog post. 该博客文章中还有一个解决方案。

Thanks to Rick Strahl for the solution, and @Andrew Sklyarevsky for referring :D 感谢Rick Strahl的解决方案,以及@Andrew Sklyarevsky的推荐:D

Reference and Complete Description: http://www.west-wind.com/weblog/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats 参考和完整说明: http//www.west-wind.com/weblog/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats

I solved the issue, and thus the solution, is adding following codes to Global.asax : 我解决了这个问题,因此解决方案是将以下代码添加到Global.asax

protected void Application_Error(object sender, EventArgs e)
{
    // Remove any special filtering especially GZip filtering
    Response.Filter = null;
…
}

Or even better 甚至更好

protected void Application_PreSendRequestHeaders()
{
// ensure that if GZip/Deflate Encoding is applied that headers are set
// also works when error occurs if filters are still active
HttpResponse response = HttpContext.Current.Response;
if (response.Filter is GZipStream && response.Headers["Content-encoding"] != "gzip")
    response.AppendHeader("Content-encoding", "gzip");
else if (response.Filter is DeflateStream && response.Headers["Content-encoding"] != "deflate")
    response.AppendHeader("Content-encoding", "deflate");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM