Implementation of viewstate filtering when asp.net generates static data

Source: Internet
Author: User

Copy codeThe Code is as follows:
Public static string GetSourceTextByUrl (string url)
{
WebRequest request = WebRequest. Create (url );
Request. Timeout = 200000; // Timeout in 20 seconds
WebResponse response = request. GetResponse ();
Stream resStream = response. GetResponseStream ();
StreamReader sr = new StreamReader (resStream );
String tempstr = sr. ReadToEnd ();

Regex r1 = new Regex ("<input type = \" hidden \ "name = \" _ EVENTTARGET \ ". */>", RegexOptions. IgnoreCase );
Regex r2 = new Regex ("<input type = \" hidden \ "name = \" _ EVENTARGUMENT \ ". */>", RegexOptions. IgnoreCase );
Regex r3 = new Regex ("<input type = \" hidden \ "name = \" _ VIEWSTATE \ ". */>", RegexOptions. IgnoreCase );
// Filter <form> code
Regex r4 = new Regex ("<form name = \" aspnetForm \ ". * id = \" aspnetForm \ ">", RegexOptions. IgnoreCase );
Regex r5 = new Regex ("</form> ");
Tempstr = r1.Replace (tempstr ,"");
Tempstr = r2.Replace (tempstr ,"");
Tempstr = r3.Replace (tempstr ,"");
Tempstr = r4.Replace (tempstr ,"");
Tempstr = r5.Replace (tempstr ,"");

Return tempstr;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.