ASP.NET 4.0驗證請求 A potentially dangerous Request.Form value was detected from the client (ctl00$MainC

來源:互聯網
上載者:User

A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$txtCode="<code></code>").

Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. To allow pages to override application request validation settings, set requestValidationMode="2.0" in the configuration section. After setting this value, you can then disable request validation by setting validateRequest="false" in the Page directive or in theconfiguration section. However, it is strongly recommended that your application explicitly check all inputs in this case. For more information, see http://go.microsoft.com/fwlink/?LinkId=153133.

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$txtCode="<code></code>").

Version Information: Microsoft .NET Framework Version:4.0.21006; ASP.NET Version:4.0.21006.1

 

在安裝了Visual Studio 2010 Beta2之後,當頁面輸入框預設情況下輸入“<”或者“>”的時候。按照存取原則,這將導致一些安全問題,諸如:跨站指令碼攻擊(cross-site scripting attack)。而這個問題的更準確描述則是,當你在安裝了.NET Framework 4.0以上版本後,當你的應用程式以.NET Framework 4.0為架構版本,你的任意伺服器請求,都將被進行伺服器請求驗證(ValidationRequest),這不僅包括ASP.NET,同時也包括Web Services等各種HTTP請求,不僅僅針對aspx頁面,也針對HTTP Handler,HTTP Module等,因為這個驗證(Valify)的過程,將會發生在BeginRequest事件之前。

基於以上原理,在ASP.NET之前的版本中,請求驗證也是預設開通的,但是發生在頁面級(aspx)的,並且只在請求執行的時候生效,因此,在舊的版本中,我們只需要按以下方式配置即可:

在頁面層級(aspx中)設定
ValidateRequest="false"
或者
在全域層級(Web.config中)設定
<configuration>
    <system.web>
        <pages  validateRequest="false">

但是,以上設定僅對ASP.NET4.0以上有效。在ASP.NET4.0版本上,我們需要更多一行的配置:

在全域層級(Web.config中)設定
<configuration>
    <system.web>
        <httpRuntime  requestValidationMode="2.0">

這一點其實在發生錯誤的頁面中已經有說明了。在實際使用過程中,不僅如此,而且我發現requestValidationMode只要設定成小於4.0就可以,比如:1.0,2.0,3.0,3.9都是可以的,錯誤提示中指明用2.0,目的只是說明用ASP.NET 2.0的預設進行工作。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.