2012-10-31 50 views
1

我正在處理一些ASP.NET應用程序。在發生一些故障或錯誤的情況下,我得到一些奇怪的錯誤屏幕。錯誤頁面顯示是這樣的:ASP.net中奇怪的錯誤屏幕應用程序

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

等等....

的應用目前正處於測試階段,因此,我已經離開了差錯屏幕從web.config中可見。任何人遇到同樣的問題,並得到了問題和解決方案?

回答

2

由於瑞克施特拉爾的溶液中,並且@Andrew Sklyarevsky用於參照:d

參考而完整描述:http://www.west-wind.com/weblog/posts/2011/May/02/ASPNET-GZip-Encoding-Caveats

我解決了問題,並且因此溶液中,在添加以下代碼來Global.asax

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

甚至更​​好

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"); 
}