使用正则Regex来移除网页的ViewState(转)

原文地址:http://www.cnblogs.com/insus/articles/1422675.html

重写Page的Render方法

 

protected override void Render(HtmlTextWriter writer)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        HtmlTextWriter hWriter = new HtmlTextWriter(sw);
        base.Render(hWriter);
        string html = sb.ToString();
        html = Regex.Replace(html, "<input[^>]*id=\"(__VIEWSTATE)\"[^>]*>", string.Empty, RegexOptions.IgnoreCase);
        writer.Write(html);
    }

 

 

 

 

posted @ 2013-02-23 23:38  高山-景行  阅读(168)  评论(0编辑  收藏  举报