asp.net輸出重寫壓縮分頁檔執行個體代碼

來源:互聯網
上載者:User

 這篇文章主要介紹了asp.net輸出重寫壓縮分頁檔執行個體代碼,需要的朋友可以參考下

例子  代碼如下:using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.htmlControls;using System.Text.RegularExpressions;using System.IO;/// <summary>/// PageBase 頁面基類/// </summary>public class PageBase : System.Web.UI.Page{    protected override void Render(htmlTextWriter writer)    {        StringWriter sw = new StringWriter();        HtmlTextWriter htmlWriter = new htmlTextWriter(sw);        base.Render(htmlWriter);        string html = sw.ToString();        html = Regex.Replace(html, “[f v]“, “”);        html = Regex.Replace(html, ” {2,}”, ” “);        html = Regex.Replace(html, “>[ ]{1}”, “>”);        writer.Write(html);    }}  補充幾款.net壓縮模組 一、WebResourceCompression壓縮模組  這個壓縮模組是專門用來即時壓縮ASP.NET2.0頁面引用的所有*.axd資源,一般aspx頁面使用了如anthem.net的ajax架構或 asp.net驗證控制項都會產生axd檔案引用,這個檔案實際就是一個js指令碼,啟用這個壓縮模組後,所有的axd資源都會被GZIP壓縮後再傳送給用戶端,此模組特別適用於aspx頁面應用了ajax架構或需引用體積龐大的axd資源檔的項目! 使用:解壓後將WebResourceCompression.dll放到網站項目的BIN目錄,並且在Web.config <httpModules> 配置節中加入以下語句: 代碼如下:  代碼如下:<add name="WebResourceCompression" type="WebResourceCompression.WebResourceCompressionModule"/> 優點:使用簡單 缺點:僅支援ASP.NET2.0或以上版本,不能壓縮除axd外的其它資源! 二、PageCompression壓縮模組   與之前的模組不同,這個模組是專門用來壓縮aspx頁面的,啟用這個壓縮模組之後,aspx頁面將會被即時壓縮,一般100K的頁面能被壓縮到25K左右,此模組適用於只需要對頁面進行壓縮的項目! 使用:解壓後將Compression.PageCompressionModule.dll放到網站項目的BIN目錄,並且在Web.config <httpModules> 配置節中加入以下語句: 代碼如下: 代碼如下:<add name="PageCompressionModule" type="Compression.PageCompressionModule,Compression.PageCompressionModule"/> 優點:使用簡單 缺點:僅支援ASP.NET2.0或以上版本,不能壓縮除aspx頁面外的其它資源,而且啟用壓縮後,頁面引用的axd資源會無效(BUG)! 三、HttpCompress6.0壓縮模組   這是一個支援asp.net1.0/1.1/2.0(2.0以下版本不支援gzip壓縮,僅支援deflate壓縮),可以壓縮aspx頁面請求的所有類型(MimeTypes)的資源,包括圖片、js指令碼、axd、aspx頁面、css檔案等,並且能在web.config詳細自訂要壓縮那種類型的資源及不壓縮那種類型的資源、也可定義要壓縮指定的頁面或不壓縮指定的頁面,另外還有壓縮比率設定(high|normal|low)等等強大的自訂功能,不過此控制項的最嚴重問題是在asp.net2.0下啟用壓縮會導致axd檔案無效,這樣如果頁面應用了ajax架構就會導致ajax功能失效。 使用:略(與下面推薦的CompressionModule壓縮模組使用方法雷同) 優點:開放原始碼,強大的自訂功能,支援asp.net1.0/1.1/2.0版本,能壓縮多種資源! 缺點:使用複雜,asp.net2.0下啟用壓縮會導致axd檔案無效! 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.