title: Gzip compression not working ASP.net MVC5
body: <p>I want to compress my web application with Gzip and I am using following class</p>
  
  <p><strong>compression filter</strong></p>
  
  <pre><code>public class CompressFilter : ActionFilterAttribute
  {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          HttpRequestBase request = filterContext.HttpContext.Request;
          string acceptEncoding = request.Headers["Accept-Encoding"];
          if (string.IsNullOrEmpty(acceptEncoding)) return;
          acceptEncoding = acceptEncoding.ToUpperInvariant();
          HttpResponseBase response = filterContext.HttpContext.Response;
          if (acceptEncoding.Contains("GZIP"))
          {
              response.AppendHeader("Content-encoding", "gzip");
              response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
          }
          else if (acceptEncoding.Contains("DEFLATE"))
          {
              response.AppendHeader("Content-encoding", "deflate");
              response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
          }
      }
  }
  </code></pre>
  
  <p><strong>cache filter</strong></p>
  
  <pre><code>public class CacheFilterAttribute : ActionFilterAttribute
  {
      public int Duration
      {
          get;
          set;
      }
  
      public CacheFilterAttribute()
      {
          Duration = 1;
      }
  
      public override void OnActionExecuted(ActionExecutedContext filterContext)
      {
          if (Duration &lt;= 0) return;
  
          HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
          TimeSpan cacheDuration = TimeSpan.FromMinutes(Duration);
  
          cache.SetCacheability(HttpCacheability.Public);
          cache.SetExpires(DateTime.Now.Add(cacheDuration));
          cache.SetMaxAge(cacheDuration);
          cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
      }
  }
  </code></pre>
  
  <p><strong>controller</strong></p>
  
  <pre><code>[CompressFilter]
  [CacheFilter(Duration = 60)]
  public ActionResult Index()
  {}
  </code></pre>
  
  <p>and applying this class to Action in Controller. But in firebug it's still showing <strong>"Transfer-Encoding: chunked"</strong> , but it should be <strong>"Transfer-Encoding: gzip"</strong>.</p>
  
  <p><strong>I am testing it on localhost.</strong></p>
  
  <p>Please tell me what am I doing wrong? Thanks and Regards. </p>
  
  <p><strong>update</strong> cache filter is working fine, but still no gzip compression, below is response header in chrome.</p>
  
  <pre><code>Cache-Control:public, must-revalidate, proxy-revalidate, max-age=3600
  Content-Type:text/html; charset=utf-8
  Date:Wed, 22 Jul 2015 13:39:06 GMT
  Expires:Wed, 22 Jul 2015 14:39:04 GMT
  Server:Microsoft-IIS/10.0
  Transfer-Encoding:chunked
  X-AspNet-Version:4.0.30319
  X-AspNetMvc-Version:5.1
  X-Powered-By:ASP.NET
  X-SourceFiles:=?UTF-8?B?QzpcVXNlcnNcQXJiYXpcRG9jdW1lbnRzXFZpc3VhbCBTdHVkaW8gMjAxM1xQcm9qZWN0c1xidXlwcmljZXNwYWtpc3RhblxCdXlQaG9uZQ==?=
  </code></pre>
  
  <p>Is there any way I can make this work, I really need help guys, Thanks</p>