Several types were found that match the controller named "Home." (Two areas, same controller name)

This is probably a duplicate for many, but the obvious answers in them do not solve my problem.

I get:

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter. The request for 'Home' has found the following matching controllers: App.Web.Controllers.HomeController App.Web.Areas.Mobile.Controllers.HomeController 

I set the default namespace for my HomeController in Global.ascx.cs:

  routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults new string[] { "App.Web.Controllers.HomeController" } ); 

(verified that App.Web.Controllers.HomeController is not a typo).

And also registered Mobile HomeController in MobileAreaRegistration:

 public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Mobile_default", "Mobile/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } 

So why am I still seeing the error message? I built / cleaned and ran again. All the same result.

This is how I register my routes:

 protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } 
+6
source share
1 answer

In your Global.asax route registration, for obvious reasons, replace:

 new string[] { "App.Web.Controllers.HomeController" } 

from:

 new string[] { "App.Web.Controllers" } 

This is a namespace limitation that you should use there, not a specific type.

+14
source

Source: https://habr.com/ru/post/906563/


All Articles