“ExceptionMessage”:“找到了与请求匹配的多个操作

时间:2016-05-16 10:52:55

标签: c# .net asp.net-web-api

我有两种方法,它们都是没有参数的GET方法:

[HttpGet]
    [ActionName("ProductsTypes")]
    public dynamic ProductsTypes()
    {
        DbConnection.Connect();
        var result = DbConnection.GetProductsTypes();
        DbConnection.Disconnect();
        return result;
    }

    [HttpGet]
    [ActionName("ProductsInfo")]
    public dynamic ProductsInfo()
    {
        DbConnection.Connect();
        var result = DbConnection.GetProductsInfo();
        DbConnection.Disconnect();
        return result;
    }

我将路线定义为:

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { action="get", id = RouteParameter.Optional }
        );

每种方法的网址是:

http://localhost:14775/api/shekem/ProductsInfo for the ProductsInfo method
http://localhost:14775/api/shekem/ProductsTypes for the ProductsTypes method

然而,我一直收到这个错误:

{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nProductsTypes on type ShekemService.Controllers.ShekemController\r\nProductsInfo on type ShekemService.Controllers.ShekemController","ExceptionType":"System.InvalidOperationException","StackTrace":"   at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}

0 个答案:

没有答案