Response.Filter属性:网站内容的GZIP压缩

Response.Filter属性:在数据发送出去前通过绑定的Filter来修改HTTP实体数据

应用场景(网站内容的GZIP压缩,多语言实现等等。。。)

定义:public Stream Filter{get;set;}

例如,实现网页压缩传输:

 

string str = Request.Headers.Get("Accept-Encoding");   
if (str != null)   
{   
    Stream filter = Response.Filter;   
    str = str.ToLower();   
    if (str.Contains("gzip"))   
    {   
        Response.Filter = new GZipStream(filter, CompressionMode.Compress);   
        Response.AppendHeader("Content-Encoding", "gzip");   
    }   
    else if (str.Contains("deflate"))   
    {   
        Response.Filter = new DeflateStream(filter, CompressionMode.Compress);   
        Response.AppendHeader("Content-Encoding", "deflate");   
    }   
}  

你可能感兴趣的:(response)