MVC ValidateInput(false)页面验证失效的解决方案

ASP.NET MVC3 RC Bug 解决方案

毫无疑问这是一个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 }
复制代码

转载于:https://www.cnblogs.com/llhhll/p/5159829.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值