MVC5學習筆記 BindAttribute


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






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM