我遇到以下错误:
找到了与控制器匹配的多种类型 命名'测试'。如果为此请求提供服务的路由,则会发生这种情况 (' JIB / api / {controller} / {action}')发现定义了多个控制器 具有相同名称但不同的名称空间,不受支持。 请求'测试'找到了以下匹配的控制器: WebApplication2.Areas.JIB.Controllers.TestController WebApplication2.Areas.JCB.Controllers.TestController System.InvalidOperationException 在 System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage 请求) System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()
[Route("JIB/api/Test/test")]
[HttpGet]
public IHttpActionResult Test()
{
return Ok("JIBs");
}
--------------
[Route("JCB/api/Test/test")]
[HttpGet]
public IHttpActionResult Test()
{
return Ok("JCB");
}
---------------
Global.asax
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
JCBAreaRegistration.RegisterAllAreas();
// GlobalConfiguration.Configure(WebApiConfig.Register);
RegisterRoutes(RouteTable.Routes);
}
JCBAreaReges context.Routes.MapHttpRoute( 名称:" JCBApiAction", routeTemplate:" JCB / api / {controller} / {action}" );
context.Routes.MapHttpRoute(
name: "JCBApi",
routeTemplate: "JCB/api/{controller}"
);
//****************=======Default Route=========*******************
context.MapRoute(
"JCB_dashboard",
"JCB/{controller}/{action}/{id}",
new { Controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
);
context.MapRoute(
"JCB_default",
"JCB/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
JIBAreaReges context.Routes.MapHttpRoute( 名称:" JIBApiAction", routeTemplate:" JIB / api / {controller} / {action}" );
context.Routes.MapHttpRoute(
name: "JIBApi",
routeTemplate: "JIB/api/{controller}"
);
//****************=======Default Route=========*******************
context.MapRoute(
"JIB_dashboard",
"JIB/{controller}/{action}/{id}",
new { Controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
);
context.MapRoute(
"JIB_default",
"JIB/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);