【转】MVC5学习笔记 BindAttribute

  1. // POST: Movies/Create
  2. // 为了防止“过多发布”攻击,请启用要绑定到的特定属性,有关
  3. // 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
  4. [HttpPost]
  5. [ValidateAntiForgeryToken]
  6. publicActionResultCreate([Bind(Include="ID,Title,ReleaseDate,Genre,Price")]Movie movie)
  7. {
  8. if(ModelState.IsValid)
  9. {
  10. db.Movies.Add(movie);
  11. db.SaveChanges();
  12. returnRedirectToAction("Index");
  13. }
  14. returnView(movie);
  15. }

其中[Bind(Include="ID,Title,ReleaseDate,Genre,Price")]The Bind attribute is another important security mechanism that keeps hackers from over-posting data to your model.

大意是:BindAttribute 是一个防止黑客“OverPost”攻击的重要安全机制。
"OverPost": 其实就是使用表单提交工具模拟提交时,手动加一些奇怪的东西。Form Post时,RequestBody是ID=1&Title=123&ReleaseDate=20150502&Genre=Science&Price=10&HHH=test。“HHH=test”就是“over-posting”了。详细可查看: Over Posting Note

原文地址:https://www.cnblogs.com/hycms/p/9123707.html