代码之家  ›  专栏  ›  技术社区  ›  tags2k

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

  •  16
  • tags2k  · 技术社区  · 16 年前

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

    garble garble
    (来源: x01.co.uk )

    我试着去勾搭 Application_Error 试图删除GZip头,但没有效果。如何在出错时反转GZipping?

    2 回复  |  直到 7 年前
        1
  •  21
  •   AlfeG    15 年前

    我知道这个问题已经过时了。

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

    希望这对任何人都有帮助。

        2
  •  3
  •   Vaibhav Garg    15 年前

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