Web Api调用遇到错误提示System.Web.HttpException (0x80004005): The controller for path '' was not f

2022-02-09 13:48:23.603 +08:00 [ERR] 
System.Web.HttpException (0x80004005): The controller for path '/UK_60_Dev_RecognitionApi/Redemption/CheckOutOrder/1' was not found or does not implement IController.
   在 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
   在 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
   在 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
   在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   在 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

因为调用的 controller是基于ApiController实现的。

而api的配置是,

 public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

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

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
        }
    }

 

所以,只需要在调用的url里面,补上api路由就可以,改为

/UK_60_Dev_RecognitionApi/api/Redemption/CheckOutOrder/1

 

上一篇:C#使用chrome浏览器(CefSharp)


下一篇:手把手教你用Golang封装一款适合自己使用的Web编程框架