现在的位置: 首页 > 综合 > 正文

去掉asp.net自动生成的垃圾代码的一个类,

2013年03月20日 ⁄ 综合 ⁄ 共 1029字 ⁄ 字号 评论关闭

using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.UI;

/// <summary>
/// Summary description for StaticPageInfo
/// </summary>
public class StaticPageInfo : System.Web.UI.Page
{
    protected override void Render(HtmlTextWriter writer)
    {
        StringWriter sw = new StringWriter();

        base.Render(new HtmlTextWriter(sw));

        string html = sw.ToString();
        html = ReplaceView(html);
        writer.WriteLine(html.Trim());
    }
    public string ReplaceView(string BodyHtml)
    {
        BodyHtml = Regex.Replace(BodyHtml, @"<form([\s|\S]*?)>([\s|\S]*?)</form>", @"$2", RegexOptions.IgnoreCase);
        BodyHtml = Regex.Replace(BodyHtml, @"<input type=""hidden"" name=""__VIEWSTATE""([\s|\S]*?)/>", @"", RegexOptions.IgnoreCase);
        BodyHtml = Regex.Replace(BodyHtml, @"<input type=""hidden"" name=""__EVENTVALIDATION""([\s|\S]*?)/>", @"", RegexOptions.IgnoreCase);
        BodyHtml = Regex.Replace(BodyHtml, @"<form([\s|\S]*?)>([\s|\S]*?)</form>", @"$2", RegexOptions.IgnoreCase);
 
        return BodyHtml;
    }
}

抱歉!评论已关闭.