在ASP.NET / IIS7中使用Gzip输出错误页面

时间:2010-03-10 10:43:27

标签: asp.net gzip

我在我的网站上实施了Rick Strahl's GZipEncodePage方法,它对网站本身非常有用。但是,当我的代码抛出异常时,“服务器错误”页面看起来像这样:

garble garble http://x01.co.uk/garbled_garble.gif

为了删除GZip标题,我试图挂钩Application_Error,但无济于事。如何在出错时反转GZipping?

2 个答案:

答案 0 :(得分:21)

我明白这个问题确实已经过时了。

On Application_Error从Response中删除过滤器,如下所示

 protected void Application_Error(Object sender, EventArgs e)
 {
    HttpApplication app = sender as HttpApplication;
    app.Response.Filter = null;
 }

希望这有助于任何人。

答案 1 :(得分:3)

在我的情况下,我把它放在我的基页类中,如下所示:

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;
    }
}
相关问题