46

are these things the same?

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

if not where is a difference?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
r.r
  • 7,023
  • 28
  • 87
  • 129

2 Answers2

57

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
24

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.

Todd Menier
  • 37,557
  • 17
  • 150
  • 173
rashleighp
  • 1,226
  • 1
  • 13
  • 21
  • 1
    I'm dealing with one reason myself -- I've just discovered an Update endpoint that only accepts the POST verb. In order to switch it to PUT, I have to accept both verbs for a few builds until all the clients are updated. – Eric Lloyd Oct 14 '15 at 17:20
  • +1 for *you can use `[AcceptVerbs]` to accept other verbs that are not part of the HttpVerbs enum - eg. `[AcceptVerbs("Trace")]`* – mmushtaq Jul 19 '17 at 06:04