Asp.net mvc 来自React应用程序的Web Api调用出现System.InvalidOperationException错误

Asp.net mvc 来自React应用程序的Web Api调用出现System.InvalidOperationException错误,asp.net-mvc,reactjs,asp.net-web-api,asp.net-web-api2,Asp.net Mvc,Reactjs,Asp.net Web Api,Asp.net Web Api2,我有这两个Web Api控制器,我目前正在从react应用程序调用控制器方法,GetSingle public IHttpActionResult GetAllData() { var modelitems = new List<TestModel>(); var items = AWEntity.GetProducts(); var i = 0; foreach (var item in items

我有这两个Web Api控制器,我目前正在从react应用程序调用控制器方法,
GetSingle

    public IHttpActionResult GetAllData()
    {
        var modelitems = new List<TestModel>();

        var items = AWEntity.GetProducts();
        var i = 0;

        foreach (var item in items)
        {
            var model = new TestModel
            {
                Id = item.ProductId,
                TestName = item.Name,
                TestMessage = "My Message" + i,
                ReorderPoint = item.ReorderPoint
            };

            modelitems.Add(model);

            i++;
        }

        return Ok(modelitems);
    }

    public IHttpActionResult GetSingle()
    {
        var item = AWEntity.GetProduct();

        var model = new TestModel
        {
            Id = item.ProductId,
            TestName = item.Name,
            TestMessage = "My Message" + 1,
            ReorderPoint = item.ReorderPoint
        };

        return Ok(model);
    }
我的WebApi路由配置如下所示:

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

        config.Routes.MapHttpRoute(
            name: "API Default",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional });
所以,我的问题是,每当我调用
GetSingle
方法时,我都会得到这个错误 在控制台中

    {
  "message": "An error has occurred.",
  "exceptionMessage": "Multiple actions were found that match the request: \r\nGetData on type WebAPIComponent.Controllers.TestApiController\r\nGetSingle on type WebAPIComponent.Controllers.TestApiController",
  "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()"
}
{
“消息”:“发生错误。”,
“exceptionMessage”:“找到多个与请求匹配的操作:\r\nWebapicComponent.Controllers.TestapicController类型上的nGetData\r\nWebapicComponent.Controllers.TestapicController类型上的NGETGoogle”,
“异常类型”:“System.InvalidOperationException”,
“stackTrace”:“在System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelector或CacheItem.SelectAction(HttpControllerContext controllerContext)\r\n在System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext controllerContext)上(HttpControllerContext controllerContext,CancellationToken CancellationToken)\r\n位于System.Web.Http.Dispatcher.HttpControllerDispatcher.d_u1.MoveNext()
}
如果不知道原因是什么,我尝试在默认路由中添加另一个路由,其中包括action参数,但这似乎不起作用,如果可能的话,我希望避免使用自定义路由属性


多谢大家

啊,我找到了答案,路线配置设置错误,带有动作的配置应该优先考虑

    {
  "message": "An error has occurred.",
  "exceptionMessage": "Multiple actions were found that match the request: \r\nGetData on type WebAPIComponent.Controllers.TestApiController\r\nGetSingle on type WebAPIComponent.Controllers.TestApiController",
  "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()"
}