Reputation: 149
I want to build a Web API which accepts a string parameter and return a string value,but I always get the error, The requested resource does not support HTTP method GET
. I searched a bit in the stack overflow and added the line [AcceptVerbs("GET")]
but I still got the error. Could any one help me out?
Global.asax.cs file
config.Routes.MapHttpRoute(
name: "sasRoute",
routeTemplate: "api/sas/{container}",
defaults: new
{
controller = "sas",
container = RouteParameter.Optional
}
);
Controller's method
[Route("{container}")]
[AcceptVerbs("GET")]
[HttpGet]
public string GetContainerToken(string container)
{
return container;
}
Upvotes: 1
Views: 3219
Reputation: 62260
You do not need to register Custom Route, as you already have Attribute Route.
Remove it from your code. Instead, you will need RoutePrefix.
[RoutePrefix("api/sas")]
public class SasController : ApiController
{
[Route("{container}")]
public string Get(string container)
{
return container;
}
}
Upvotes: 3