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

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

重写Page的Render方法

使用正则Regex来移除网页的ViewState_第1张图片

 

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

 

 

 

 

你可能感兴趣的:(regex)