16

I've implemented Rick Strahl's GZipEncodePage method on my site and it works great for the site itself. However, when my code throws an exception the "Server Error" page looks something like this:

garble garble
(source: x01.co.uk)

I've tried to hooking into Application_Error in an effort to remove the GZip headers but to no avail. How I can reverse the GZipping on error?

2 Answers 2

21

I'm understand that this question is really outdated.

On Application_Error remove Filters from Response, like this

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

Hope this helps anybody.

Sign up to request clarification or add additional context in comments.

2 Comments

For anyone wondering where exactly to put this code ... dumping it into Global.asax.cs works wonders. It also prevents you from needing to remember to inherit from a specific class (as per Vaibhav's answer) because it is used application-wide. Succinct, effective, perfect.
stackoverflow.com/a/4548466/319980 suggests using app.Response.Filter.Dispose() rather than just assigning it to null.
3

In my case I put this in the my basepage class like so:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.