天天看點

解決.Net 4.0 A potentially dangerous Request.Form value was detected from the client 異常解決更新至.net4後出現A potentially dangerous Request.Form value was detected from the client (轉載)

解決ASP.NET 4.0  

"A potentially dangerous Request.Form value was detected from the client". 錯誤

在.net中,Request時出現有HTML或Javascript等字元串時,系統會認為是危險性值。立馬報錯。

(在.aspx檔案頭中加入這句: <%@ Page validateRequest="false" %>,但還是出現相同錯誤)

或是修改web.config檔案: 

<configuration> 

<system.web> 

    <pages validateRequest="false" /> 

</system.web> 

</configuration>

但錯誤依舊。

對.NET 4.0, 應該加上requestValidationMode="2.0" to the httpRuntime configuration section of the web.config :

<httpRuntime requestValidationMode="2.0"/>(這句重要)

結構:<configuration>

           <system.web>

             <httpRuntime  requestValidationMode="2.0">

  使用者在頁面上送出表單到伺服器時,伺服器會檢測到一些潛在的輸入風險,例如使用富文本編輯器控件(RichTextBox、FreeTextBox、CuteEditor等)編輯的内容中包含有HTML标記或腳本标記,ASP.NET頁面會抛出一個"A potentially dangerous Request.Form value was deceted from the client"的異常。這個是ASP.NET頁面為了防範頁面注入功能的一種保護機制,要取消這種保護,正常的做法是在.aspx檔案的<%@Page %>部分加入ValidateRequest="false"屬性。但是從.NET 4.0開始你可能需要多修改一個地方,在網站的web.config檔案中加入這行配置:

   同時,你還需要確定頁面上使用者輸入的部分不會存在任何注入攻擊的代碼,常用的做法是使用Encode處理。

<a href="http://www.cnblogs.com/wenjie/archive/2011/06/13/2079785.html">http://www.cnblogs.com/wenjie/archive/2011/06/13/2079785.html</a>

繼續閱讀