1

请求的网址:http://localhost/api/access/blob

路线:

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

定义的动作:

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";
    }
}

结果:

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

为什么它没有找到合适的行动?

4

1 回答 1

3

您必须删除DefaultApiWebApiConfig.cs 文件中的路由配置。仅添加您的配置:

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

它将与 url 一起使用:

http://localhost/api/access/blob

http://localhost/api/access/queue

于 2013-01-30T23:19:47.630 回答