Asp.net gzip壓縮的啟用方法詳解

來源:互聯網
上載者:User

首先,我們需要下載DC.Web.HttpCompress.dll,將它引用到我們的asp.net項目中。接下來在web.config中簡單的配置一下,就可以實現gzip壓縮了,需要配置的地方如下:

 代碼如下 複製代碼

  <sectionGroup name="DCWeb">
        <section name="HttpCompress" type="DC.Web.HttpCompress.Configuration,DC.Web.HttpCompress"/>
    </sectionGroup>
</configSections>

<!--配置gzip的壓縮-->

 代碼如下 複製代碼

<DCWeb>
    <HttpCompress compressionType="GZip">
        <!--設定jspath及csspath,如果刪除掉這行配置的話就會使用預設值-->
        <PathSettings jsPath="javascript" cssPath="css"/>
        <IncludedMimeTypes>
            <add mime="text/html"/>
            <add mime="image/gif"/>
            <add mime="image/jpeg"/>
            <add mime="text/css"/>
            <add mime="application/x-javascript"/>
        </IncludedMimeTypes>
        <!--配置不壓縮何種類型資源請使用:
            <ExcludedMimeTypes>
                <add mime="text/html" />
            </ExcludedMimeTypes>
            注意:ExcludedMimeTypes及IncludedMimeTypes只需要配置一個就可以,如果像上面那樣配置ExcludeMimeTypes的話,則表明除html類型的資源外,其它資源都會被壓縮-->
        <!--<ExcludedPaths>
        設定不啟用壓縮的頁面路徑,下面設定了nocompress目錄下的default.aspx頁面將不會啟用壓縮功能,但其它頁面則正常啟用壓縮
        <add path="~/NoCompress/Default.aspx"/>
        </ExcludedPaths>-->
    </HttpCompress>
</DCWeb>
<add name="HttpCompressModule" type="DC.Web.HttpCompress.HttpModule,DC.Web.HttpCompress"/>

到這我們就實現了Asp.net gzip壓縮,下邊看看我在本地的測試結果,你可以使用Google Chrome瀏覽器查看是否啟用gzip壓縮,使用Ctrl+Shift+J即可開啟,點擊Resources查看檔案,

除了上面的方法之外我們還可以使用iis開啟gzip壓縮了,這裡我就不介紹了大家可到本站的windows伺服器頻道去找。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.