There is no difference in this two snippets of code, they have the same purpose, so that the method only accepts requests from verb
GET
, in fact one is abbreviation of the other. In the code source of Httpgetattribute it is quite clear that it is the abbreviation for Acceptverbsattribute:
Code Httpgetattribute:
using System.Reflection;
namespace System.Web.Mvc
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public sealed class HttpGetAttribute : ActionMethodSelectorAttribute
{
private static readonly AcceptVerbsAttribute _innerAttribute =
new AcceptVerbsAttribute(HttpVerbs.Get);
public override bool IsValidForRequest(ControllerContext controllerContext,
MethodInfo methodInfo)
{
return _innerAttribute
.IsValidForRequest(controllerContext, methodInfo);
}
}
}
Source and authorship rights Copyright (c) Microsoft Open Technologies, Inc. All Rights reserved in the link
An advantage of using attribute AcceptVerbs()
is that it may contain more than one type of verb
configured, example:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
or
[AcceptVerbs("GET", "POST")]
thus the method accepts requests from verb
GET
or POST
in the example.
Remarks: Remember that if there is no configuration ([HttpGet]
, [HttpPost]
or [AcceptVerbs("POST")]
, etc.) the default accepted method is verb
GET
References: