Do I still need the AcceptedVerbs attribute?
-
26-12-2019 - |
题
In WebApi2, do I still need to decorate my methods with the AcceptedVerbs attribute? Or is the HttpPut parameter in the Route attribute sufficient?
[AcceptVerbs("PUT")]
[Route("api/v1/tokens/current"), HttpPut]
Thanks guys.
解决方案
HttpPut
is actually a separate attribute here and not a parameter on RouteAttribute
. For your scenario you could use either AcceptVerbs
or HttpPut
, but in general AcceptVerbs
is helpful when you want to define multiple http methods or custom http methods which by default do not have strongly typed representation in Web API (ex: HttpPut). I would prefer using HttpPut
in your above scenario.
不隶属于 StackOverflow