通过action对文件流压缩,提高带宽速度!!!
引用using System.IO.Compression;
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext.HttpContext.Request.Headers["Accept-Encoding"].Contains("deflate")) { filterContext.HttpContext.Response.AppendHeader("content-encoding", "deflate"); filterContext.HttpContext.Response.Filter = new DeflateStream(filterContext.HttpContext.Response.Filter, CompressionMode.Compress); } //base.OnActionExecuting(filterContext); }
未加特性之前
加完特性之后
呵呵你可以在FilterConfig 在定义一个全局配置。