2017-01-12 139 views
0

我有一個MVC5 Web應用程序。我用我的控制器上的壓縮過濾器從This SiteMVC頁面上的壓縮過濾器不起作用

一切正常,但看起來像我的網頁仍然沒有壓縮。 我使用YSlow Chrome擴展程序檢查我的頁面,但它報告GZip壓縮不適用於我的頁面。我正在使用IIS Express在VS 2015(調試模式)中測試我的Web應用程序。

我做錯了什麼?或YSlow擴展是錯誤的?

+0

或許這可以幫助? - http://stackoverflow.com/questions/31529076/gzip-compression-not-working-asp-net-mvc5 –

+0

或者,也許這樣? - http://stackoverflow.com/questions/10102743/gzip-response-on-iis-express –

+0

第二個解決方案是不優選的,因爲我最終想要將我的應用程序部署在虛擬主機上,我沒有IIS上的控制權。對於第一個鏈接,我已經嘗試過了,它看起來是一個非常好的解決方案,但是我的應用程序在Web託管中不穩定。我會再試一次。謝謝 – FLICKER

回答

0

在你的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>