Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:37:39+00:00 2026-05-26T19:37:39+00:00

I am experiencing an issue where, when a server error occurs in my web

  • 0

I am experiencing an issue where, when a server error occurs in my web application, I see a gzip’ed server error rendered to the screen, not the actual error message. I am attempting to resolve this by calling GZIP Decompress on Application_Error.

I am unable to decompress the HttpContext.Current.Response stream because it is not able to be read. That is, CanRead is false, but CanWrite is true. This leads me to believe I am doing something wholly incorrect, so I am also open for suggestions.

protected void Application_Error(object sender, EventArgs e)
{
    if (HttpContext.Current.Error != null)
    {
        this.GetType().GetLogger().Error(HttpContext.Current.Error);
    }

    CompressionManager.Decompress();
}

public static void Decompress()
{
    //Determine types of compression possible.
    string acceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
    if (string.IsNullOrEmpty(acceptEncoding)) return;

    //Make sure the stream is actually compressed.
    HttpResponse response = HttpContext.Current.Response;
    bool compressed = response.Headers.AllKeys.Contains("Content-encoding");
    if (!compressed) return;

    acceptEncoding = acceptEncoding.ToUpperInvariant();

    using ( MemoryStream memStream = new MemoryStream() )
    {
        byte[] buffer = new byte[1024];
        int byteCount;
        do
        {
            byteCount = response.Read(buffer, 0, buffer.Length);
            memStream.Write(buffer, 0, byteCount);
        } while (byteCount > 0);

        // If you're going to be reading from the stream afterwords you're going to want to seek back to the beginning.
        memStream.Seek(0, SeekOrigin.Begin);

        if (acceptEncoding.Contains("GZIP"))
        {
            using (GZipStream decompress = new GZipStream(memStream, CompressionMode.Decompress))
            {
                decompress.CopyTo(response.Filter);
            }
        }
        else if (acceptEncoding.Contains("DEFLATE"))
        {
            response.Filter = new DeflateStream(response.Filter, CompressionMode.Decompress);
        }

        response.Headers.Remove("Content-encoding");
    }
}

I’ve been googling for a while now, but have not made much progress. As far as I can tell I should be working with “Request.GetResponseStream()” and not the response object, but I think GetResponseStream requires a non-static Request.

Open to anything. Thanks.

Derp. Just do this:

CompressionManager.Decompress(HttpContext.Current.Error.Message);

public static void Decompress(string errorMsg)
{
    HttpContext.Current.Response.Filter = new DeflateStream(new MemoryStream(ASCIIEncoding.Default.GetBytes(errorMsg)), CompressionMode.Compress);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:37:40+00:00Added an answer on May 26, 2026 at 7:37 pm

    I would suggest you do a Response.Clear and then set the appropriate headers, then send the data. It is correct that you cannot read the response stream this way.

    It might be that your response stream is compressed by settings in IIS and that you cannot change this through code. Update the IIS compression settings and try again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am experiencing a strange issue with connecting to my web server from my
I'm experiencing what I believe is a circular dependency issue with my PHP application.
Im experiencing an issue with a production server. I can connect to the server
I've been looking into an issue i'm experiencing when posting to a server, specifically
I'm currently experiencing a strange issue that my understanding of SQL server doesn't quite
We're experiencing a strange issue with our local NuGet package server. Over time, it
I'm experiencing issues when trying to communicate with a web server (Apache 2.2.17) using
We are experiencing an issue where our sql server where cpu usage jumps to
I'm experiencing an issue on a test machine running Red Hat Linux (kernel version
I'm experiencing an issue with ActiveMQ and would like to trace/view all ActiveMQ activity.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.