ASP.NET MVC 3 RC ValidateInput(false)頁面驗證失效的解決方案

來源:互聯網
上載者:User

毫無疑問這是一個bug,很多使用者升級到rc時都遇到了這個問題,以前很正常的提交只要帶有html標籤就被報"...從用戶端中檢測到有潛在危險的 request.form 值。"即使在web.config中禁用頁面驗證也會出現這個問題.

成因和部分解決方案見:

ASP.NET MVC 3裡面用戶端輸入驗證的改動 

另一解決方案見:

http://weblogs.asp.net/imranbaloch/archive/2010/11/14/mvc-3-rc-bug-and-quick-solution.aspx

我採用後者的解決方案:

1,後台頁面中增加using System.Web.Helpers;的引用 

2,修改請求的httppost方法:

之前:

 1 public ActionResult ActionA(FormCollection form1)
 2 {
 3     return View();
 4 }
 5 public ActionResult ActionB(int i,FormCollection form)
 6 {
 7     return View();
 8 }
 9 public ActionResult ActionC(int i, FormCollection formABC, string j, [Bind(Include = "Name,Address")] Student s)
10 {
11     return View();
12 }
13 public ActionResult ActionD(int i, string j,FormCollection f , string k, string t)
14 {
15     return View();
16 }
17 public ActionResult ActionE(FormCollection form123, string t, string t2)
18 {
19     return View(new Student { Age = 30, Name = "Akbar" });
20 }

 

 之後:

 1 public ActionResult ActionA()
 2 {
 3     FormCollection form1 = new FormCollection(Request.Unvalidated().Form);
 4     return View();
 5 }
 6 public ActionResult ActionB(int i)
 7 {
 8     FormCollection form = new FormCollection(Request.Unvalidated().Form);
 9     return View();
10 }
11 public ActionResult ActionC(int i, string j, [Bind(Include = "Name,Address")] Student s)
12 {
13     FormCollection formABC = new FormCollection(Request.Unvalidated().Form);
14     return View();
15 }
16 public ActionResult ActionD(int i, string j, string k, string t)
17 {
18     FormCollection f  = new FormCollection(Request.Unvalidated().Form);
19     return View();
20 }
21 public ActionResult ActionE( string t, string t2)
22 {
23     FormCollection form123 = new FormCollection(Request.Unvalidated().Form);
24     return View(new Student { Age = 30, Name = "Akbar" });
25 }

 

 解決!應該會在正式版中除掉這個bug.

 希望本文能對您有所協助!

相關文章

聯繫我們

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