2013-12-17 4 views
2

사용자가 "/ Linecard"또는 "/ Manufacturers"를 URL로 사용하여 ASP.Net MVC 사이트의 "/ Linecard"페이지에 액세스 할 수있게하려고합니다. , 2 개의 다른 가능한 URL.MVC : 1 개의 컨트롤러에 대한 다중 경로

나는 다음과 같은 추가하는 시도 : 전혀 작동하지 않습니다 "기본"경로 후이 추가

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

나는 "/ 제조자"로 이동할 때 404 오류가 발생합니다. "기본값"이 작동하기 전에 넣기 만하지만 첫 번째로 일치하므로 메뉴 링크를 클릭하면 "/ 제조업체"만 URL에 표시됩니다. "/ Linecard"를 URL로 항상 표시하고 싶습니다.

모든 포인터? 이 작업을 수행하는 데 사용할 수있는 특정 제약이 있습니까? 감사!

답변

4

확장 기능이없는 URL로 이동할 때도 동일한 문제가있었습니다. 우리는 확장이 가능한 하나의 경로를 계속 지원할 필요가있었습니다. 내 기본 경로는 말과 같은에서 기본값하여 경로를 매핑 할 때 당신은 또한 순서를 설정할 수있는 예외

routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
    // if controller specified does not match 'manufacturers' (case insensitive) 
    new { controller = "^((?i)(?!manufacturers).)*$" }, 
    new string[] { "Namespace.Of.Controllers" } 
); 

routes.MapRoute(
    "Manufacturers", // Route name 
    "Manufacturers/{action}/{id}", // URL with parameters 
    new { controller = "Linecard", action = "Index", id = UrlParameter.Optional }, 
    new string[] { "Namespace.Of.Controllers" } 
); 
+0

우수 ... 내가 원했던 그대로. 고맙습니다! –

0

을 위해 특별히 그 매핑 한 후, 기존의 URL을 제외한 모든에 적용함으로써 주위 있어요 so

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

routes.MapRoute(
    "Default", // Route name 
    "{controller}/{action}/{id}", // URL with parameters 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
); 
관련 문제