1

나는 이것을 알 수 없다.MVC C# 컨트롤러 충돌 (사이트 관리자와 사이트 전면)

어떻게 문제를 해결할 수 있습니까? RegisterArea로 영역을 선언 할 때

AdminAreaReistration CS

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

RouteConfig

 public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional } 
     ); 
    } 

enter image description here

+0

어떻게 오류가 생성되는? 특정 URL로 이동하려고하거나 'Url.Action'과 같은 URL을 생성하려고합니까? –

답변

1

오류 이미지에 따르면, 당신은 기본 경로와 사이에 이름 충돌을 피하기 위해 서로 다른 네임 스페이스를 사용할 수있다 지역 경로 :

AdminAreaRegistration.cs

public override void RegisterArea(AreaRegistrationContext context) 
{ 
    context.MapRoute(
     "CMSAdmin_default", 
     "CMSAdmin/{controller}/{action}/{id}", 
     new { action = "Index", id = UrlParameter.Optional }, 
     new[] { "cms.site.Areas.CMSAdmin.Controllers" } // Insert area namespace here 
    ); 
} 

RouteConfig.cs

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

    routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}", 
     defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional }, 
     namespaces: new[] { "cms.site.Controllers" } // Insert project namespace here 
    ); 
} 
Multiple types were found that match the controller name 오류에서

가능한 원인 : (이것은 현재의 문제 가능성이) 서로 다른 영역과 동일한 컨트롤러 이름을 사용

1),

2) 프로젝트 네임 스페이스/어셈블리 이름의 이름 바꾸기 (이전 프로젝트 이름 DLL 파일 삭제 bin/bin 디렉토리에 복사 한 다음 다시 정리하고 다시 작성하십시오.) 3) 이름이 같지 만 버전이 다른 참조가 충돌합니다 (예전 참조를 제거한 후 리팩터링).

참고 :

Multiple types were found that match the controller named 'Home'

Having issue with multiple controllers of the same name in my project

+0

감사합니다. 이 문제에 매우 명확하게 답변 한 사람은 귀하뿐입니다. :) 제 1 기사의 문제점 –