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

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

posted @ 2011-06-07 14:24  你妹的sb  阅读(415)  评论(2编辑  收藏  举报
百度一下