【问题标题】:Compression Filter on MVC Page is not workingMVC 页面上的压缩过滤器不起作用
【发布时间】:2017-01-12 18:50:54
【问题描述】:

我有一个 MVC5 Web 应用程序。我在我的控制器上使用了来自This Site的压缩过滤器

一切正常,但看起来我的页面仍未压缩。 我使用 YSlow Chrome 扩展程序来检查我的页面,但它报告说我的页面上没有应用 GZip 压缩。我正在使用 IIS Express 在 VS 2015(调试模式)中测试我的 Web 应用程序。

我做错了吗?还是 YSlow 扩展错误?

【问题讨论】:

  • 第二种解决方案不是首选,因为我最终希望将我的应用程序部署在我无法控制 IIS 的 Web 托管上。对于第一个链接,我已经尝试过了,它看起来是一个非常好的解决方案,但我的应用程序在虚拟主机上不稳定。我会再试一次。谢谢

标签: asp.net-mvc http-compression yslow asp.net-mvc-filters


【解决方案1】:

在您的 web.config 中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <httpCompression>
      <dynamicTypes>
        <clear />
        <add enabled="true" mimeType="text/*"/>
        <add enabled="true" mimeType="message/*"/>
        <add enabled="true" mimeType="application/x-javascript"/>
        <add enabled="true" mimeType="application/javascript"/>
        <add enabled="true" mimeType="application/json"/>
        <add enabled="false" mimeType="*/*"/>
        <add enabled="true" mimeType="application/atom+xml"/>
        <add enabled="true" mimeType="application/atom+xml;charset=utf-8"/>
      </dynamicTypes>
      <staticTypes>
        <clear />
        <add enabled="true" mimeType="text/*"/>
        <add enabled="true" mimeType="message/*"/>
        <add enabled="true" mimeType="application/javascript"/>
        <add enabled="true" mimeType="application/atom+xml"/>
        <add enabled="true" mimeType="application/xaml+xml"/>
        <add enabled="true" mimeType="application/json"/>
        <add enabled="false" mimeType="*/*"/>
      </staticTypes>
    </httpCompression>
  </system.webServer>
</configuration>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    相关资源
    最近更新 更多