1

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;
}
3
  • What URL are you attempting? Commented Jul 22, 2016 at 20:52
  • @PaulAbbott localhost:52896/api/sas/test Commented Jul 22, 2016 at 20:59
  • You should try: [Route("/api/mobile/{container}")] [HttpGet] public string GetContainerToken(string container) { return container; } Commented Jul 22, 2016 at 21:06

1 Answer 1

3

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.