private static void ServeSitemapContent( string domainDataCode, DateTime lastModDate, bool isModified) { var response = HttpContext.Current.Response; var maxAge = new TimeSpan(24, 0, 0); // 24 hours -- used in headers var expiration = DateTime.UtcNow + maxAge; response.Cache.SetCacheability(HttpCacheability.Public); response.Cache.SetETag( '"' + lastModDate.Ticks.ToString(CultureInfo.InvariantCulture) + '"'); response.Cache.SetLastModified(lastModDate); response.Cache.SetMaxAge(maxAge); response.Cache.SetExpires(expiration); response.Cache.SetSlidingExpiration(false); if (isModified) // serve actual sitemap { var sitemap = Sitemap.GetSitemapXml(domainDataCode); if (sitemap == null || sitemap.Length == 0) { throw new VoteException("No sitemap for {0}", domainDataCode); } response.ContentType = "text/xml"; response.ContentEncoding = Encoding.UTF8; response.BinaryWrite(sitemap); } else // tell client to use cached version { response.StatusCode = 304; // Explicitly set the Content-Length header so the client doesn't wait for // content but keeps the connection open for other requests response.AddHeader("Content-Length", "0"); } }