• mvc 文件压缩 减少文件大小


     1 using System;
     2 using System.Collections.Generic;
     3 using System.IO.Compression;
     4 using System.Linq;
     5 using System.Web;
     6 using System.Web.Mvc;
     7 
     8 namespace PaiXie.Pos.Admin {
     9     /// <summary>
    10     /// 文件压缩 
    11     /// </summary>
    12     public class CompressFilter : ActionFilterAttribute {
    13         public override void OnActionExecuting(ActionExecutingContext filterContext) {
    14             HttpRequestBase request = filterContext.HttpContext.Request;
    15 
    16             string acceptEncoding = request.Headers["Accept-Encoding"];
    17 
    18             if (string.IsNullOrEmpty(acceptEncoding)) return;
    19 
    20             acceptEncoding = acceptEncoding.ToUpperInvariant();
    21 
    22             HttpResponseBase response = filterContext.HttpContext.Response;
    23 
    24             if (acceptEncoding.Contains("GZIP")) {
    25                 response.AppendHeader("Content-encoding", "gzip");
    26                 response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
    27             }
    28             else if (acceptEncoding.Contains("DEFLATE")) {
    29                 response.AppendHeader("Content-encoding", "deflate");
    30                 response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
    31             }
    32         }
    33     }
    34 }
  • 相关阅读:
    插入排序
    JavaMail学习笔记
    汉诺塔问题
    使用Three.js绘制一个虚拟城市
    jquery flotcharts使用简介
    用CSS hack技术解决浏览器兼容性问题.
    IE条件注释详解.
    让IE6也认识!important
    代码重构(转)
    模版+数据分离渲染方式的设计与实现
  • 原文地址:https://www.cnblogs.com/lyl6796910/p/5213341.html
Copyright © 2020-2023  润新知