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

C# ASP.net应用程序中的奇怪错误屏幕,c#,asp.net,error-handling,C#,Asp.net,Error Handling,我正在开发一些ASP.NET应用程序。在一些故障或错误的情况下,我会得到一些奇怪的错误屏幕。错误页面显示如下内容: ��`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��/> ��`我�%&/M�{J�J��T��`$ؐ@��

我正在开发一些ASP.NET应用程序。在一些故障或错误的情况下,我会得到一些奇怪的错误屏幕。错误页面显示如下内容:

��`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��/>
��`我�%&/M�{J�J��T��`$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�不���?
\fdl��J�ɞ!���?~|?"��安永�')=��y6�����H��贮
�:�v�˼n��E:��,M�Wy�����
等等


该应用程序目前处于测试阶段,因此,我在web.config中留下了可见的错误屏幕。任何遇到相同问题的人,都可以找到问题和解决方案吗?

请查看您正在使用的ASP.NET应用程序是否使用了某种形式的自动GZip压缩,您的错误页面让人想起RickStrahl在这里描述:。在那篇博文中也有一个解决方案。

检查您正在使用的ASP.NET应用程序是否使用某种形式的自动GZip压缩,您的错误页面非常让人想起Rick Strahl在这里描述的内容:。在那篇博文中也有一个解决方案。

感谢Rick Strahl提供的解决方案,和@Andrew Sklyarevsky的推荐:D

参考和完整说明:

我解决了这个问题,因此解决方案是将以下代码添加到
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");
}

感谢Rick Strahl提供的解决方案和@Andrew Sklyarevsky提供的参考:D

参考和完整说明:

我解决了这个问题,因此解决方案是将以下代码添加到
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");
}

是的,你是对的,我正在使用HTTP压缩(GZIP),也感谢你的解决方案。我非常感谢你的帮助。是的,你是对的,我正在使用HTTP压缩(GZIP),也感谢你的解决方案。我非常感谢你的帮助。