HttpPost vs HttpGet attributes in MVC: Why use HttpPost?

前端 未结 4 931
灰色年华
灰色年华 2020-11-28 07:24

So we have [HttpPost], which is an optional attribute. I understand this restricts the call so it can only be made by an HTTP POST request. My question is why would I want

4条回答
  •  悲&欢浪女
    2020-11-28 08:14

    As far as best practices for HttpGet and HttpPost, it is good practice in any web development to use HttpPost for Creates, Updates, and Deletes (data modification). Post are good, because they require a form submission, which prevents users from clicking poisoned links(e.g. [https://www.mysite.com/Delete/1]) in emails, social sites, etc. and changing data inadvertently. If you are basically just Reading data HttpGet works great.

    See OWASP for more in-depth security considerations and why the validation token increases security.

提交回复
热议问题