title: Gzip compression setting for asp.net with jquery post
body: <p>In my application, I do a jquery post which gets an array of json objects. What are the settings that i need to make both on iis7.5 and json?</p>
  
  <p>I made a custom httpmodule </p>
  
  <pre><code>private void Compress(object sender, EventArgs e)
          {
              HttpApplication app = (HttpApplication)sender;
              HttpRequest request = app.Request;
              HttpResponse response = app.Response;
  
              //Ajax Web Service request is always starts with application/json
              if (request.ContentType.ToLower(CultureInfo.InvariantCulture).StartsWith("application/json"))
              {
                  //User may be using an older version of IE which does not support compression, so skip those
                  if (!((request.Browser.IsBrowser("IE")) &amp;&amp; (request.Browser.MajorVersion &lt;= 6)))
                  {
                      string acceptEncoding = request.Headers["Accept-Encoding"];
  
                      if (!string.IsNullOrEmpty(acceptEncoding))
                      {
                          acceptEncoding = acceptEncoding.ToLower(CultureInfo.InvariantCulture);
  
                          if (acceptEncoding.Contains("gzip"))
                          {
                              response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                              response.AddHeader("Content-encoding", "gzip");
                          }
                          else if (acceptEncoding.Contains("deflate"))
                          {
                              response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                              response.AddHeader("Content-encoding", "deflate");
                          }
                      }
                  }
              }
          }
  </code></pre>
  
  <p>In jquery post, i added</p>
  
  <pre><code>$.ajax({
      type: "POST", //GET or POST or PUT or DELETE verb
      url: newGrid.Serviceurl, // Location of the service
      data: JSON.stringify(newGrid), //Data sent to server
      contentType: newGrid.contenttype, // content type sent to server
      dataType: "json", //Expected data format from server
      processdata: true, //True or False
      beforeSend: function (request) {
          request.setRequestHeader("Accept-Encoding", "gzip");
      },
      success: function (result) { // get an array of json objects 
          alert('done');
      }
   });
  </code></pre>
  
  <p>web.config changes -</p>
  
  <pre><code>&lt;httpModules&gt;
    &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/&gt;
    &lt;add name="GzipCompression" type="GzipCompression"/&gt;
  &lt;/httpModules&gt;
  </code></pre>
  
  <p>Is there any other config changes that i need to make.</p>