【发布时间】:2009-11-13 16:07:56
【问题描述】:
您好,我需要从 ASHX 提供 GZ 压缩文件。在代码中,我已经清楚地知道了字符串:
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();
}
现在我需要
- 在 GZ 中压缩 xml(用于压缩站点地图文件 http://www.sitemaps.org/protocol.php#sitemapXMLExample)
- 将其发送到 Response.OutputStream
- 设置一些 HTTP 响应标头(内容类型、编码、ecc。)
有什么帮助吗?
【问题讨论】:
-
我们不是按需生成文件,而是按计划生成文件。因为我们的站点地图包含近一百万个 URL,所以这些数据非常多。我们在生成文件时压缩内容,然后将文件存储在 cdn 上,以便在前端请求时提供服务。