2012-01-09 4 views
14

저는 프로젝트에 두 개의 영역이 있습니다. 내가 여기에 몇 가지 소스를 발견'Home'컨트롤러와 일치하는 여러 유형이 발견되었습니다. - 두 개의 다른 영역에서

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: 
BaseAdminMVC.Areas.BaseAdmin.Controllers.HomeController 
BaseAdminMVC.Areas.TitomsAdmin.Controllers.HomeController 

: 나는이 프로그램을 실행할 때 지금은이 오류를 얻을 Multiple Controller name
을하지만 그것은 단지 하나 개의 영역 작동 생각합니다.
제 경우에는 다른 영역에 두 개의 프로젝트가 있습니다. 누군가가 문제를 해결하기 위해 무엇을해야하는지 말할 수 있기를 바랍니다.
가 여기에 Global.asax 파일입니다

public static void RegisterRoutes(RouteCollection routes) 
     { 
      string[] namespaces = new string[] { "BaseAdminMVC.Areas.BaseAdmin.Controllers", "BaseAdminMVC.Areas.TitomsAdmin.Controllers"}; 

      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
      routes.MapRoute(
       "Default", // Route name 
       "{controller}/{action}/{id}", // URL with parameters 
       new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
       namespaces 
      ); 
     } 

그런데, 나는 또한 Area 폴더 외부 ("HomeController")를 컨트롤러했다. 이것은 단지 두 개의 프로젝트 BaseAdminTitomsAdmin에 대한 링크를 제공합니다.

나는이 솔루션을 시도,하지만 여전히 작동하지 않습니다

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
      routes.MapRoute(
       "Default", // Route name 
       "{controller}/{action}/{id}", // URL with parameters 
       new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
      ); 

      routes.MapRoute(
       "BaseAdmin", 
       "BaseAdmin/{controller}/{action}", 
       new { controller = "Account", action = "Index" }, 
       new string[] { "BaseAdminMVC.Areas.BaseAdmin.Controllers" } 
      ); 

      routes.MapRoute(
       "TitomsAdmin", 
       "TitomsAdmin/{controller}/{action}", 
       new { controller = "Home", action = "Index" }, 
       new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" } 
      ); 

사전에 감사!

+1

편집 : 기본 경로를 아래로 (마지막 위치로) 이동해야합니다. 여기에서 주문이 중요합니다. –

+0

@HenkHolterman 여전히 작동하지 않았다. – fiberOptics

+0

"작동하지 않는다"는 것은 아직 명확하지 않습니다. –

답변

18

나는 일이 무엇인지 모르겠지만,이 코드는 잘 작동 : 내 프로젝트 네임 스페이스/어셈블리의 이름 변경을 수행 한 후이 오류가 발생했습니다

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    routes.MapRoute(
     "Default", // Route name 
     "{controller}/{action}/{id}", // URL with parameters 
     new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
     new string[] { "BaseAdminMVC.Areas.TitomsAdmin.Controllers" } 
    ); 
} 
+28

단지 chiming in .. (그리고 저는 1 년 늦었습니다), 출력 어셈블리와 기본 네임 스페이스의 이름을 변경했기 때문에이 오류가 발생했습니다. MVC3 사이트의 오래된 컴파일 된 어셈블리를 프로젝트의 디버그/bin 폴더에 그대로 두었습니다. 사이트가로드되면 이전 어셈블리와 새롭게 이름이 바뀐 어셈블리에서 홈 컨트롤러를 가져 와서 동일한 오류가 발생했습니다. 짧게 짧게 말해서, 나는 빈에 들어가서 오래된 어셈블리를 제거하고 모든 것이 완벽하게 작동하기 시작했습니다. – OFConsulting

+0

고마워요! 지금 4.0에서 .Net 4.5로 마이그레이션 중입니다. 동일한 오류가 다시 표시되면 도움말을 참조하십시오. – fiberOptics

+1

@OFConsulting 나는 "감사합니다"라고 말하면 안되지만, FU - * - 고맙습니다! – Ydhem

6

.

네임 스페이스/어셈블리의 이름을 변경하면 bin 폴더에 이전 이름의 나머지 어셈블리/dll이있을 수 있습니다. 그냥 거기에서 삭제하고 작동합니다.

2

프로젝트를 마우스 오른쪽 단추로 클릭하고 프로젝트를 선택하십시오. 그렇지 않으면 bin 디렉토리를 완전히 비운 다음 다시 빌드하십시오. 왼쪽 위에있는 어셈블리가 없어야합니다.

관련 문제