asp.net输出重写压缩页面文件的实例

发布时间:2020-10-30编辑:脚本学堂
本文介绍下,用asp.net实现输出重写压缩页面文件的例子,供大家学习参考。

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