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 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 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

这次就能访问了。

你可能感兴趣的:(.net,core,webapi报错)