Validaterequest=false can disable request validation

Source: Internet
Author: User

See the MVP using WebClient and WebRequest classes to get the Web page source code so want to write their own point, of course, refer to its approach.

This time I downloaded the Visual Web Developer

The code was written in the previous article,

My btn function is as follows

String urlpage = "";
Urlpage = Urltext.text;
WebRequest request = WebRequest.Create (urlpage);
WebResponse response = Request. GetResponse ();
Stream Resstream = Response. GetResponseStream ();
StreamReader sr = new StreamReader (Resstream, System.Text.Encoding.Default);
Contenthtml.text =SR. ReadToEnd ();
Resstream.close ();
Sr. Close ();

But a debug run found a mistake

A Potentially dangerous Request.Form value is detected from the client

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been . This value could indicate an attempt to compromise the security of your application, such as a cross-site scripting. You can disable request validation by setting Validaterequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application the check all explicitly in the this case.

Exception Details: System.web.httprequestvalidationexception:a potentially dangerous Request.Form value is detected from the client (Conte Nthtml= "<met ... ").

Carefully looked for the solution and the problem of the reasons for the original is validaterequest, the following is the network of reference connections, write very detailed, very good hehe

Http://access911.net/index.asp?board=4&recordid=71FAB51E15DCE7F3

Http://support.microsoft.com/default.aspx?scid=kb;en-us;821343&Product=aspnet

According to the above, the solution is three kinds,

1. ValidateRequest of static page

<%@ Page validaterequest= "false"%>

2. Set Web.config

<configuration>
<system.web>
<pages validaterequest= "false"/>
</system.web>
</configuration>

3. I personally think that the best, is the use of Server.HTMLEncode this method

I changed the following

String urlpage = "";
Urlpage = Urltext.text;
WebRequest request = WebRequest.Create (urlpage);
WebResponse response = Request. GetResponse ();
Stream Resstream = Response. GetResponseStream ();
StreamReader sr = new StreamReader (Resstream, System.Text.Encoding.Default);
Contenthtml.text = Server.HTMLEncode (sr. ReadToEnd ());
Resstream.close ();
Sr. Close ();

OK, run it, fix it. Not bad

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.