Asp – Which to use: “AcceptGet, AcceptPost”(MvcContrib) vs. AcceptVerbs(ASP.NET Mvc)

asp.net-mvc

In ASP.NET MVC controller methods can be decorated to accept on specific HTTP Methods(Get, Post, Get.. etc). Between MvcContrib and ASP.NET MVC there are 3 classes: "AcceptGet, AcceptPost" and AcceptVerbs. All three: "AcceptGet, AcceptPost" and AcceptVerbs do the same thing. They specify what http method is allowed to access a action/method.

AcceptGet and AcceptPost are in the MvcContrib. While 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)

Documentation for the MvcContrib project's AcceptPost can be found here.

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

ASP.NET MVC released with AcceptVerbs which takes an enum:

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

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

Best Answer

I don't think there's a great deal of difference between the two implementations but given that

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

is part of the framework now, I always use this. Both are strongly typed so there's no real difference there, and the HttpVerbs enum includes Delete, Head and Put which aren't in the MVC contrib version.