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