An unhandled exception occurred while processing the request 解決辦法

webapi報錯:

An unhandled exception occurred while processing the request.

AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:

HcyDevServer.Controllers.UserInfoController.Get (HcyDevServer)
HcyDevServer.Controllers.UserInfoController.Get (HcyDevServer)

Microsoft.AspNetCore.Mvc.Internal.ActionSelector.SelectBestCandidate(RouteContext context, IReadOnlyList<ActionDescriptor> candidates)

  • AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied: HcyDevServer.Controllers.UserInfoController.Get (HcyDevServer) HcyDevServer.Controllers.UserInfoController.Get (HcyDevServer)

    • Microsoft.AspNetCore.Mvc.Internal.ActionSelector.SelectBestCandidate(RouteContext context, IReadOnlyList<ActionDescriptor> candidates)

    • Microsoft.AspNetCore.Mvc.Internal.MvcAttributeRouteHandler.RouteAsync(RouteContext context)

    • Microsoft.AspNetCore.Routing.Tree.TreeRouter.RouteAsync(RouteContext context)

    • Microsoft.AspNetCore.Routing.RouteCollection.RouteAsync(RouteContext context)

    • Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)

    • Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

解決辦法,指定action就可以了。    

//[Route("api/[controller]")]
  [Route("api/[controller]/[action]/")]

訪問比如:https://localhost:44366/api/userinfo/FindUser?username=eee&sex=1

這次就能訪問了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章