What to use: "AcceptGet, AcceptPost" (MvcContrib) and AcceptVerbs (ASP.NET Mvc)?

In ASP.NET, MVC controllers can be decorated for reception by certain HTTP methods (Get, Post, Get .., etc.). There are 3 classes between MvcContrib and ASP.NET MVC: "AcceptGet, AcceptPost" and AcceptVerbs. All three: "AcceptGet, AcceptPost" and AcceptVerbs do the same. They indicate which http method is allowed to access the action / method.

AcceptGet and AcceptPost are in MvcContrib. Although AcceptVerbs is native to the Mvc framework. Which is better to use?

AcceptGet / AcceptPost (MvcContrib)

/// <returns></returns> [AcceptGet] public ActionResult Profile(string id) 

AcceptVerbs (ASP.NET Mvc)

 /// <returns></returns> [AcceptVerbs(HttpVerbs.Get)] public ActionResult EditRequest(string id) 

The documentation for the MvcContrib AcceptPost project can be found here .

It looks like AcceptGet and AcceptPost were created to fill the gap in one of the earlier versions of the ASP.NET Mvc framework. The AcceptGet and AcceptPost classes provided the strongly typed HttpMethod attribute.

ASP.NET MVC released with AcceptVerbs, which accepts an enumeration:

 [Flags] public enum HttpVerbs { Delete = 8, Get = 1, Head = 0x10, Post = 2, Put = 4 } 

My question is which one is the best implementation, AcceptGet / AcceptPost or AcceptVerbs (with the HttpVerbs enum type)?

+4
source share
2 answers

I do not think that there is a big difference between the two implementations, but on the condition that

 [AcceptVerbs(HttpVerbs.Get)] public ActionResult EditRequest(string id) 

is now part of the structure, I always use this. Both of them are strongly typed, so there is no real difference, and the HttpVerbs enumeration includes Delete, Head and Put, which are not in the MVC contrib version.

+5
source

Starting with ASP.Net MVC 2 Preview 1, the following attributes are in the main MVC structure: HttpPost, HttpGet, HttpDelete, HttpPut. Of course, the AcceptVerbs attribute is still supported.

So, if you are using MVC 2, you can use these new attributes and not require the MVC version Contrib AcceptPost and AcceptGet.

+2
source

All Articles