asp.net mvc - [HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post/Get)]

后端 未结 2 1796
生来不讨喜
生来不讨喜 2020-12-09 01:05

are these things the same?

[HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post/Get)]

if not where is a difference?

相关标签:
2条回答
  • 2020-12-09 01:34

    Yes, absolutely the same. [HttpPost/HttpGet] were introduced in ASP.NET MVC 2 to reduce the keystrokes we have to type :-) [AcceptVerbs(HttpVerbs.Post/Get)] could still be used and behave the same although if you are writing new code I would recommend the first.

    0 讨论(0)
  • 2020-12-09 01:39

    Yes they are the same but with the newer versions you can only make an action accept requests from one verb. Using [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get | HttpVerbs.Delete)] you can accept 2 or more. Also you can use [AcceptVerbs] to accept other verbs that are not part of the HttpVerbs enum - eg. [AcceptVerbs("Trace")].

    I'm not sure why you would ever need to use this functionality but you are able to should you wish.

    0 讨论(0)
提交回复
热议问题