下面内容段是关于通过Filter对asp.net页面进行GZip压缩的内容,希望能对各朋友有一些用处。
if (!Request.UserAgent.ToLower().Contains("konqueror"))
{
if (Request.Headers["Accept-encoding"] != null &&
Request.Headers["Accept-encoding"].Contains("gzip"))
{
Response.Filter = new GZipStream(Response.Filter,
CompressionMode.Compress, true);
Response.AppendHeader("Content-encoding", "gzip");
}
else if (Request.Headers["Accept-encoding"] != null &&
Request.Headers["Accept-encoding"].Contains("deflate"))
{
Response.Filter = new DeflateStream(Response.Filter,
CompressionMode.Compress, true);
Response.AppendHeader("Content-encoding", "deflate");
}
}