国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net輸出重寫壓縮頁面文件的小例子

2024-07-10 13:15:47
字體:
來源:轉載
供稿:網友

不知你是否留意過,有一些網站的html代碼都是混在一起,沒有任何空格和換行等多余字符。它的好處不用多說——界面大小絕對優化。或許您在想,他們這樣做大大降低了可讀性。的確,我們看是很亂,只能借用第三方軟件重新布局代碼。但是,我想他們開發時使用的源碼不可能是混一團,前不久發現一個頁面基類,大概可以解釋這個問題,不多說,看源碼:

復制代碼 代碼如下:


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);
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金昌市| 焉耆| 酒泉市| 乾安县| 馆陶县| 浑源县| 开化县| 金昌市| 治县。| 定西市| 山西省| 武夷山市| 富宁县| 镶黄旗| 杨浦区| 桐城市| 当阳市| 武平县| 洛宁县| 芦溪县| 伽师县| 齐河县| 应用必备| 绵竹市| 榆社县| 宜章县| 贵南县| 玛纳斯县| 东源县| 绥江县| 涪陵区| 碌曲县| 若羌县| 息烽县| 南澳县| 德惠市| 双桥区| 怀集县| 红桥区| 弥渡县| 红安县|