MVC:從用戶端中檢測到有潛在危險的 Request.Form 值 的解決方案

來源:互聯網
上載者:User

標籤:還需   ast   log   post方法   mvc   解決   版本   頭部   master   

1,在出現該錯誤的頁面頭部的page中加入ValidateRequest="false",那麼該頁面的任何一次Post提交都不會再驗證提交內容的安全性。
如:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Manage/ViewMasterPageEdit.Master"     Inherits="System.Web.Mvc.ViewPage<MvcWebPhoto.Models.Entities.Article >" 

ValidateRequest="false" % >



2,在web.config中的pages節中配置validateRequest="false",如:

<system.web >
<pages validateRequest="false" ></pages > 
</system.web >


但這樣,整個項目中的所有Form請求都不再驗證提交內容的安全性,極不提倡這種做法。

3,如果你使用的是.Net 3.5,MVC 2.0及更高的版本,那麼可以在處理Post方法的Action添加一個特性:[ValidateInput(false)],這樣處理就更加有針對性,提高頁面的安全性。
如:

[HttpPost]
[ValidateInput(false)]
public ActionResult CatalogEdit(Catalog model)
{
return View();
}



重要
如果你使用的是MVC 3.0,那麼你會發現做了以上的設定後還是無效。這是因為你還需要在web.config中做以下設定:

<system.web >
<httpRuntime requestValidationMode="2.0" / >
</system.web >


注意:在MVC項目中,Views檔案夾下與主專案下,都會有一個web.config檔案。Views下的web.config檔案只對Views檔案夾下面的檔案有效。如果你要處理的頁面不在Views下面,那麼<httpRuntime requestValidationMode="2.0" / >一定要設定在主專案下的web.config中才有用。

MVC:從用戶端中檢測到有潛在危險的 Request.Form 值 的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.