我已经在我的网站上实现了Rick Strahl的GZipEncodePage方法,对于网站本身来说它非常有效。但是,当我的代码抛出异常时,"服务器错误"页面看起来像这样:
(来源:x01.co.uk)
我尝试通过挂钩Application_Error
来尝试删除GZip头文件,但是没有成功。我应该如何在发生错误时取消GZip压缩?
我已经在我的网站上实现了Rick Strahl的GZipEncodePage方法,对于网站本身来说它非常有效。但是,当我的代码抛出异常时,"服务器错误"页面看起来像这样:
(来源:x01.co.uk)
我尝试通过挂钩Application_Error
来尝试删除GZip头文件,但是没有成功。我应该如何在发生错误时取消GZip压缩?
我知道这个问题已经非常过时了。
在Application_Error中,从Response中删除Filters,像这样:
protected void Application_Error(Object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
app.Response.Filter = null;
}
希望这能对任何人有所帮助。
public class BasePage : System.Web.UI.Page
{
protected override void OnError(EventArgs e)
{
base.OnError(e);
System.Web.HttpContext context = System.Web.HttpContext.Current;
if (context != null && context.Response.Filter != null)
context.Response.Filter = null;
}
}
Global.asax.cs
中会产生奇妙的效果。它还可以防止您需要记住从特定类继承(根据Vaibhav的答案)因为它是应用程序范围内使用的。简洁,有效,完美。 - EAMann