感谢 Rick Strahl 的解决方案,以及 @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");
}