0

경로 데이터를 기반으로 MVC3 사이트를 현지화하고 있습니다. 예를 들어 http://domain/fr은 사이트를 프랑스어로 표시하고 http://domain은 영어로 기본 설정해야합니다 ... 아래는 Global.ascx에서 내 경로를 등록한 방법입니다.경로가 작동하지 않습니다 - ASP.NET MVC 3 URL의 현지화 로캘

내 문제는 http://domain/fr/Home/Index가 작동합니다,하지만 http://domain/Home/Index 오류를 찾을 수없는 자원을 표시하고, 조사와는 {랭}

매핑 "홈"나는 무엇을 놓치고있다 나에게 경로 테이블을 알려줍니다?

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

     routes.IgnoreRoute("favicon.ico"); 

     routes.MapRoute(
      "LogOn", // Route name 
      "Account/{action}", // URL with parameters 
      new { controller = "Account", action = "LogOn" } // Parameter defaults 
     ); 

     routes.MapRoute(
      "Localization", // Route name 
      "{lang}/{controller}/{action}", // URL with parameters 
      new { UrlParameter.Optional, controller = "Home", action = "Index"} // Parameter defaults 
     ); 

     routes.MapRoute(
      "Default", // Route name 
      "{controller}/{action}", // URL with parameters 
      new { controller = "Home", action = "Index"} // Parameter defaults 
     ); 

    } 

답변

2
routes.MapRoute(
      "Default", // Route name 
      "{controller}/{action}", // URL with parameters 
      new { controller = "Home", action = "Index"}, // Parameter defaults 
      new { controller = "[a-zA-Z]{3,}" } //regexp constraint on controller name 
     ); 

routes.MapRoute(
      "Localization", // Route name 
      "{lang}/{controller}/{action}", // URL with parameters 
      new { UrlParameter.Optional, controller = "Home", action = "Index"} // Parameter defaults 
     ); 

모든 컨트롤러 이름은 2 개 문자 :

+1

+1 regext 생각보다 더 이상 제공 트릭을 수행해야 – Laguna

관련 문제