title: Generate and serving gz compressed in ASP.NET
body: <p>Hi I need to serve from a ASHX a GZ compressed file. In the code I already have the string in clear:</p>
  
  <pre><code>public void ProcessRequest(HttpContext context)
  {
      // this is the code without compression
      HttpRequest Request = context.Request;
      HttpResponse Response = context.Response;
  
      Response.ContentEncoding = Encoding.UTF8;
      Response.ContentType = "text/xml";
  
      // this is the string to compress and send to the client
      string xml = GenerateXml();
  
      Response.Write(output);
      Response.End();
  }
  </code></pre>
  
  <p>Now and I need to </p>
  
  <ul>
  <li>compress xml in GZ (for a compressed sitemap file <a href="http://www.sitemaps.org/protocol.php#sitemapXMLExample" rel="nofollow noreferrer">http://www.sitemaps.org/protocol.php#sitemapXMLExample</a>)</li>
  <li>send it to the Response.OutputStream</li>
  <li>set some HTTP response header (content type, encoding, ecc.)</li>
  </ul>
  
  <p>Any help?</p>