zoukankan      html  css  js  c++  java
  • MVC 好记星不如烂笔头之 ---> 页面压缩GIP

     public class BaseController : Controller
    {
     /// <summary>
            /// Called before the action method is invoked.
            /// </summary>
            /// <param name="filterContext">Information about the current request and action.</param>
            protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                foreach (var iBaseService in _iBaseServiceList)
                {
                    iBaseService.Language = Language;
                }
    
                if (filterContext.HttpContext.Response.Filter == null) return;
                var acceptEncoding = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
                if (String.IsNullOrEmpty(acceptEncoding)) return;
                var response = filterContext.HttpContext.Response;
                acceptEncoding = acceptEncoding.ToUpperInvariant();
                if (acceptEncoding.Contains("GZIP"))
                {
                    response.AppendHeader("Content-Encoding", "gzip");
                    response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                }
                else if (acceptEncoding.Contains("DEFLATE"))
                {
                    response.AppendHeader("Content-Encoding", "deflate");
                    response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                }
    
                base.OnActionExecuting(filterContext);
            }
    }
  • 相关阅读:
    利用栈进行表达式的求值
    最近的一些安排
    一点碎语
    POJ 1008
    目前的进度~
    算是一个决定吧~
    C语言知识点注意事项分类整理[不定期更新]
    一年多了,该回来了……
    真悲剧
    google面试题一道
  • 原文地址:https://www.cnblogs.com/liuyunsheng/p/4128163.html
Copyright © 2011-2022 走看看