Brian D
Brian D

Reputation: 10143

My web api route map is returning multiple actions

The requested URL: http://localhost/api/access/blob

The route:

config.Routes.MapHttpRoute(
    name: "AccessApi",
    routeTemplate: "api/{controller}/{action}"
);

The defined actions:

public class AccessController : ApiController
{
    // GET api/access/blob
    [HttpGet]
    public string Blob()
    {
        return "blob shared access signature";
    }

    // GET api/access/queue
    [HttpGet]
    public string Queue()
    {
        return "queue shared access signature";
    }
}

The result:

Multiple actions were found that match the request: 
    System.String Blob() on type Project.Controllers.AccessController 
    System.String Queue() on type Project.Controllers.AccessController

Why isn't it finding the appropriate action?

Upvotes: 1

Views: 1178

Answers (1)

Felipe Oriani
Felipe Oriani

Reputation: 38618

You have to remove the DefaultApi route configuration on the WebApiConfig.cs file. Add just your configuration:

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "AccessApi",
            routeTemplate: "api/{controller}/{action}"
            );
    }
}

And it will work with the url:

http://localhost/api/access/blob

http://localhost/api/access/queue

Upvotes: 3

Related Questions