{"id":974,"date":"2013-11-27T19:37:15","date_gmt":"2013-11-27T11:37:15","guid":{"rendered":"http:\/\/www.vcoo.cc\/blog\/?p=974"},"modified":"2013-11-27T19:37:15","modified_gmt":"2013-11-27T11:37:15","slug":"asp-net-validaterequest","status":"publish","type":"post","link":"https:\/\/vcoo.cc\/blog\/974\/","title":{"rendered":"\u4ece\u5ba2\u6237\u7aef\u4e2d\u68c0\u6d4b\u5230\u6709\u6f5c\u5728\u5371\u9669\u7684Request.Form\u503c"},"content":{"rendered":"<p>\u5728\u9ad8\u7248\u672c\u7684.Net\u4e2d\u63d0\u4ea4post\u8bf7\u6c42\u63d0\u793a\u00a0asp.net \u4ece\u5ba2\u6237\u7aef\u4e2d\u68c0\u6d4b\u5230\u6709\u6f5c\u5728\u5371\u9669\u7684 Request.Form \u503c\u3002<\/p>\n<p>\u5728\u63d0\u4ea4\u8868\u5355\u65f6\u5019\uff0casp.net \u63d0\u793a\uff1a&#8221;\u4ece\u5ba2\u6237\u7aef(&#8230;&#8230;)\u4e2d\u68c0\u6d4b\u5230\u6709\u6f5c\u5728\u5371\u9669\u7684 Request.Form \u503c&#8221; \u3002asp.net\u4e2d\u7684\u8bf7\u6c42\u9a8c\u8bc1\u7279\u6027\u63d0\u4f9b\u4e86\u67d0\u4e00\u7b49\u7ea7\u7684\u4fdd\u62a4\u63aa\u65bd\u9632\u6b62XSS\u653b\u51fb\uff0casp.net\u7684\u8bf7\u6c42\u9a8c\u8bc1\u662f\u9ed8\u8ba4\u542f\u52a8\u7684\u3002\u8fd9\u4e2a\u7ed9\u51fa\u5404\u4e2a\u7248\u672c.net\u7684\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<p><strong>asp.net 2.0 \u901a\u5e38\u89e3\u51b3\u529e\u6cd5\uff1a<\/strong><\/p>\n<p><strong>\u65b9\u6848\u4e00\uff1a<\/strong><\/p>\n<p>\u5c06.aspx\u6587\u4ef6\u4e2d\u7684page\u9879\u6dfb\u52a0ValidateRequest=&#8221;false&#8221; \uff0c\u5982\u4e0b\uff1a<\/p>\n<blockquote><p>&lt;%@ Page ValidateRequest=&#8221;false&#8221; Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; CodeFile=&#8221;test2.aspx.cs&#8221; Inherits=&#8221;test2&#8243; %&gt;<\/p><\/blockquote>\n<p><strong>\u65b9\u6848\u4e8c\uff1a<\/strong><\/p>\n<p>\u4fee\u6539web.config\u914d\u7f6e\u6587\u4ef6<\/p>\n<blockquote><p>\u3000&lt;system.web&gt;<br \/>\n&lt;pages validateRequest=&#8221;false&#8221; &gt;<br \/>\n&lt;\/pages&gt;<br \/>\n&lt;\/system.web&gt;<\/p><\/blockquote>\n<p>\u603b\u7ed3\uff1avalidateRequest \u8fd9\u53e5\u6211\u4eec\u77e5\u9053\u662f\u5173\u95ed\u9a8c\u8bc1\uff0c\u4e5f\u5c31\u662f\u8bf4\u63d0\u4ea4\u5e26\u6807\u7b7e\uff0c\u6bd4\u5982 &lt;strong&gt;\u7c97\u4f53&lt;\/strong&gt; \u8fd9\u6837\u7684\u503c\u65f6\uff0cASP.NET \u4e0d\u4f1a\u62a5\u9519\u3002\u8fd9\u91cc\u63a8\u8350\u4f7f\u7528\u65b9\u6848\u4e00\uff0c\u56e0\u4e3a\u65b9\u6848\u4e00\u53ea\u4fee\u6539test.aspx\u8fd9\u4e00\u4e2a\u9875\u9762\uff1b\u800c\u5982\u679c\u4f7f\u7528\u65b9\u6848\u4e8c\u7684\u8bdd\uff0c\u5c06\u662f\u6574\u4e2a\u89e3\u51b3\u65b9\u6848\u90fd\u53d8\u6210ValidateRequest=&#8221;false&#8221; \u3002<\/p>\n<p><strong>asp.net 4.0 \u89e3\u51b3\u529e\u6cd5\uff1a<\/strong><\/p>\n<p>4.0\u548c2.0\u7684\u65b9\u6cd5\u4e00\u6837\uff0c\u4e0d\u8fc7\u8981\u6ce8\u610f\u7684\u662f\u4ece .Net Framework 4.0 \u5f00\u59cb\uff0casp.net\u5f00\u59cb\u5f3a\u5236\u68c0\u6d4bRequest\u53c2\u6570\u5b89\u5168\uff0c\u800c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 Web.config \u6765\u6062\u590d 2.0 \u7248\u672c\u7684\u6a21\u5f0f\u3002<\/p>\n<p>\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\u4fee\u6539Web.config\uff0c\u589e\u52a0requestValidationMode=&#8221;2.0&#8243;\u5c5e\u6027\u503c<\/p>\n<blockquote><p>\u3000&lt;system.web&gt;<br \/>\n<span style=\"color: #ff0000;\">&lt;httpRuntime requestValidationMode=&#8221;2.0&#8243; \/&gt;<\/span><br \/>\n<span style=\"color: #ff0000;\">\u3000\u3000&lt;pages validateRequest=&#8221;false&#8221;&gt;&lt;\/pages&gt;<\/span><br \/>\n&lt;\/system.web&gt;<\/p><\/blockquote>\n<p>4.0 \u4e2d\u591a\u4e86\u4e00\u4e2a requestValidationMode\uff0c\u8fd9\u662f\u4ec0\u4e48\u610f\u601d\u5462\uff1f<\/p>\n<p>requestValidationMode \u6709\u4e24\u4e2a\u503c\uff1a<\/p>\n<p>\u20222.0\u4ec5\u5bf9\u7f51\u9875\u542f\u7528\u8bf7\u6c42\u9a8c\u8bc1\u3002\u662f\u542f\u7528\u8fd8\u662f\u5173\u95ed\u53d6\u51b3\u4e8e validateRequest\u3002<\/p>\n<p>\u20224.0 \u9ed8\u8ba4\u503c\u3002\u4efb\u4f55 HTTP \u8bf7\u6c42\u90fd\u4f1a\u542f\u7528\u8bf7\u6c42\u9a8c\u8bc1\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e0d\u5149\u662f\u7f51\u9875\uff0c\u8fd8\u5305\u62ec Cookie \u7b49\u3002\u6b64\u65f6\u5f3a\u5236\u542f\u7528\uff0c\u4e0d\u7ba1 validateRequest \u4e3a\u4f55\u503c\u3002<\/p>\n<p>\u7531\u4e8e requestValidationMode=&#8221;4.0&#8243; \u662f\u5f3a\u5236\u542f\u7528\uff0c\u6240\u4ee5\u6211\u4eec\u4f1a\u53d1\u73b0\u5728 .NET Framework 4.0 \u4e2d\u4ec5\u9760\u8bbe\u7f6e validateRequest \u662f\u5173\u95ed\u4e0d\u4e86\u8bf7\u6c42\u9a8c\u8bc1\u7684\uff0c\u8fd8\u5f97\u5c06 requestValidationMode \u8bbe\u7f6e\u4e3a 2.0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u63d0\u4ea4\u8868\u5355\u65f6\u5019\uff0casp.net \u63d0\u793a\uff1a&#8221;\u4ece\u5ba2\u6237\u7aef(&#8230;&#8230;)\u4e2d\u68c0\u6d4b\u5230\u6709\u6f5c\u5728\u5371\u9669\u7684 Request.Form \u503c&#8221; \u3002asp.net\u4e2d\u7684\u8bf7\u6c42\u9a8c\u8bc1\u7279\u6027\u63d0\u4f9b\u4e86\u67d0\u4e00\u7b49\u7ea7\u7684\u4fdd\u62a4\u63aa\u65bd\u9632\u6b62XSS\u653b\u51fb\uff0casp.net\u7684\u8bf7\u6c42\u9a8c\u8bc1\u662f\u9ed8\u8ba4\u542f\u52a8\u7684\u3002\u8fd9\u4e2a\u7ed9\u51fa\u5404\u4e2a\u7248\u672c.net\u7684\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156,13],"tags":[195,201],"class_list":["post-974","post","type-post","status-publish","format-standard","hentry","category-server-tech","category-csharp","tag-csharp-2","tag-dotnet","cat-156-id","cat-13-id"],"_links":{"self":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/posts\/974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/comments?post=974"}],"version-history":[{"count":0,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/posts\/974\/revisions"}],"wp:attachment":[{"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/media?parent=974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/categories?post=974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vcoo.cc\/blog\/wp-json\/wp\/v2\/tags?post=974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}