title: Compression in IIS 8.5 not successful, stating ALREADY_CONTENT_ENCODING
body: <p>I am trying to debug the issue of why my pages are not being GZIP'ed or deflated according to YSLOW. I ended up enabling Failed Request Logs on the server and was able to see the failed reason of why it is not compressing, it thinks it is already compressed.</p>
  
  <pre><code>DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="ALREADY_CONTENT_ENCODING"
  </code></pre>
  
  <p>I have enabled dynamic and static compression in IIS, I have also changed the web.config file to include the following.</p>
  
  <pre><code>&lt;httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"&gt;
    &lt;scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" /&gt;
    &lt;dynamicTypes&gt;
      &lt;add mimeType="text/*" enabled="true" /&gt;
      &lt;add mimeType="message/*" enabled="true" /&gt;
      &lt;add mimeType="application/x-javascript" enabled="true" /&gt;
      &lt;add mimeType="application/json" enabled="true" /&gt;
      &lt;add mimeType="*/*" enabled="false" /&gt;
    &lt;/dynamicTypes&gt;
    &lt;staticTypes&gt;
      &lt;add mimeType="text/*" enabled="true" /&gt;
      &lt;add mimeType="message/*" enabled="true" /&gt;
      &lt;add mimeType="application/x-javascript" enabled="true" /&gt;
      &lt;add mimeType="application/atom+xml" enabled="true" /&gt;
      &lt;add mimeType="application/xaml+xml" enabled="true" /&gt;
      &lt;add mimeType="*/*" enabled="false" /&gt;
    &lt;/staticTypes&gt;
  &lt;/httpCompression&gt;
  &lt;urlCompression doStaticCompression="true" doDynamicCompression="true"/&gt;
  </code></pre>
  
  <p>In addition on my aspx page I have a method I call before every page (on page load) to run gzip compression (this might be why it is causing the error).</p>
  
  <p>This is how I call the method from the page load</p>
  
  <pre><code>//compress page
  Compression.GZipEncodePage();
  </code></pre>
  
  <p>And this is the method that compresses the page</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace InitialDataEntry
  {
      public static class Compression
      {
          /// &lt;summary&gt;
          /// Sets up the current page or handler to use GZip through a Response.Filter
          /// IMPORTANT:  
          /// You have to call this method before any output is generated!
          /// &lt;/summary&gt;
          public static void GZipEncodePage()
          {
              HttpResponse Response = HttpContext.Current.Response;
          if (IsGZipSupported())
          {
              string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
              if (AcceptEncoding.Contains("deflate"))
              {
                  Response.Filter = new System.IO.Compression.DeflateStream(Response.Filter,
                                             System.IO.Compression.CompressionMode.Compress);
                  Response.AppendHeader("Content-Encoding", "deflate");
              }
              else
              {
                  Response.Filter = new System.IO.Compression.GZipStream(Response.Filter,
                                            System.IO.Compression.CompressionMode.Compress);
                  Response.AppendHeader("Content-Encoding", "gzip");
              }
          }
  
          // Allow proxy servers to cache encoded and unencoded versions separately
          Response.AppendHeader("Vary", "Content-Encoding");
      }
  
      /// &lt;summary&gt;
      /// Determines if GZip is supported
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public static bool IsGZipSupported()
      {
          string AcceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
          string IsPartial = HttpContext.Current.Request.Headers["x-microsoftajax"];
  
          if (!string.IsNullOrEmpty(AcceptEncoding) &amp;&amp;
               AcceptEncoding.Contains("gzip") || AcceptEncoding.Contains("deflate"))
  
              //Just checking to see if this is a partial page update
              if (string.Compare("Delta=true", IsPartial, true) == 0)
              {
                  return false;
              }
              else
              {
                  return true;
              }
          else
          {
              return false;
          }
      }
  }
  }
  </code></pre>
  
  <p>This used to work by the way, but not sure when it stopped, however my users realized the issue as the pages got bloated in size and what used to be 500k is now 2mb!</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks,</p>