您的位置:首页 > 编程语言 > ASP

ASP.NET MVC 3 RC ValidateInput(false)页面验证失效的解决方案

2010-11-26 12:27 716 查看
毫无疑问这是一个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)
{
return View();
}
public ActionResult ActionD(int i, string j,FormCollection f , string k, string t)
{
return View();
}
public ActionResult ActionE(FormCollection form123, string t, string t2)
{
return View(new Student { Age = 30, Name = "Akbar" });
}

之后:

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();
}
public ActionResult ActionC(int i, string j, [Bind(Include = "Name,Address")] Student s)
{
FormCollection formABC = new FormCollection(Request.Unvalidated().Form);
return View();
}
public ActionResult ActionD(int i, string j, string k, string t)
{
FormCollection f = new FormCollection(Request.Unvalidated().Form);
return View();
}
public ActionResult ActionE( string t, string t2)
{
FormCollection form123 = new FormCollection(Request.Unvalidated().Form);
return View(new Student { Age = 30, Name = "Akbar" });
}

解决!应该会在正式版中除掉这个bug.

希望本文能对您有所帮助!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐