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 7507585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:30:59+00:00 2026-05-29T22:30:59+00:00

I have an interesting issue with a gzip/deflate ActionFilterAttribute in ASP.NET MVC 3. If

  • 0

I have an interesting issue with a gzip/deflate ActionFilterAttribute in ASP.NET MVC 3. If an exception is thrown by my application, instead of getting a YSOD, I get a full page of gibberish as seen below.

���I�%&/m�{J�J��t��$ؐ@�������iG#)�*��eVe]f@�흼��{����{����;�N’���?\fdl��J�ɞ!���?~|?”��Ey�’)=��y6�����h����Z��2k�j���uU?�+_x-��:�
�T����W�v�<[����~2�g�2���?�ʋ�y�hYՋ�������t�
_N���M�l�������{��,���Xn���Q�}��������*g�������7�� ~��j'u>K�{_��IW4�>�U�w�|=-fYzR-�������|��<&�o�Z()*�S!U��k�g�������j��.����b}��ή�9X/��J�Iն��Q���z�i�n�-g٤���ݞ��Y^����H�8/��k�}]7�ǜ@�{|�g��wUd�O����죫y���o-�����ݏ���
�ZHv,�d]��١�>o3�=�3x�7MN�����������Ow���w�.o��φ�<؟M����;���vg���A>��䋟{YޟN�����Φ�$p>q����/�!�y��9�2��two������?������Ӈ���n�9�r�^����!������{���ag�?\1*c�?!�bي
?���xI����u�f
?��{‘�����P$�v&=#s�l�_0����΃�w�ss�����廌��⼽�r���!��{k\7M���(o������4�ߛ>�>�@”|�|v���y5�����QꆦR���JSK�&�����ߛ�p������v<�C��t��1�hOI���y{j�]i���˷����
�D’p<�$,�'M��r{-�}��CF�؛�����A��9��[�½�� �!
2�� �:��!��{�t�;�߇'y��M��+�M^#x^\����Q��jM�l��?(�]�
��IZ�ݟ[����+4#"�:�X����m�������dv>������iL�̀I |�fL�TU��ho��
�{L��_t��5�o?���h�O�UY]#�u�[���G�ޞ�=���;��8���~����d�8k�w�����yw�
����ֺ��Nx��A���[��xMo��ۣf���/�Og�;y~����!

If I remove my CompressAttribute, it works as expected (I see the YSOD). So it seems that my exception handling (ElmahHandleErrorAttribute from Elmah.Contrib.Mvc) halts the remaining filters, including CompressAttribute and the response is not deflated.

Relevant code:

public sealed class CompressAttribute : ActionFilterAttribute
{
    private const string _acceptEncodingHeader = "Accept-Encoding";
    private const string _contentEncodingHeader = "Content-Encoding";

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpRequestBase request = filterContext.HttpContext.Request;

        string acceptEncoding = request.Headers[_acceptEncodingHeader];

        if (String.IsNullOrEmpty(acceptEncoding))
        {
            return;
        }

        acceptEncoding = acceptEncoding.ToUpperInvariant();

        HttpResponseBase response = filterContext.HttpContext.Response;

        if (acceptEncoding.Contains("GZIP"))
        {
            response.AppendHeader(_contentEncodingHeader, "gzip");
            response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
        }
        else if (acceptEncoding.Contains("DEFLATE"))
        {
            response.AppendHeader(_contentEncodingHeader, "deflate");
            response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
        }
    }
}

Filter registration:

GlobalFilterCollection filters = GlobalFilters.Filters;
filters.Add(new ElmahHandleErrorAttribute(), 999); // Elmah.Contrib.Mvc
filters.Add(new CompressAttribute());

How can I make sure that the response is readable even when exceptions are thrown?

  • 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-29T22:31:00+00:00Added an answer on May 29, 2026 at 10:31 pm

    This is because when there is an error in your application ASP.Net removes all your custom headers but the filter is still there. You could reset the filter on application error that should make the problem go away.

    protected void Application_Error(object sender, EventArgs e)
    {
            Response.Filter = null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have found an interesting issue between ASP.NET 3.5 and ReportViewer with Google Chrome.
I ran across an interesting issue today. We have an application that utilizes Zend
Ok I have an interesting issue on an iPad application I am developing. When
I have an interesting issue with HTTPS ports not being handled properly. It is
Someone please help. I have an interesting issue. I am trying to implement an
I have a rather interesting issue with SVG animation. I am animating along a
I have ran into an interesting issue while trying to create a more usable
I have an issue with importing the scipy.special package. It isn't harmful, just annoying/interesting.
I have an interesting issue today!! Basically I have two classes. public class A
I'm working with a db (SQL server 2008), and have an interesting issue with

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.