I am moving the site from ASP.NET MVC 1 to ASP.NET MVC 2. Currently the site supports the following routes:
/{country}/{language}/{controller}/{action} /{country}/{controller}/{action} /{language}/{controller}/{action} /{controller}/{action}
The formats for country and language differ by Regex and have suitable limitations. In MVC 1, I registered each of them as a separate route - for each of about 20 combinations. In MVC 2, I try to get the same thing that works with a single route to cover all four cases using UrlParameter.Optional , but I can't get it to work - if I define country and language as both optional, then the route /Home/Index , for example, does not match the route. This is what I am trying to do:
routes.MapRoute("Default", "{country}/{language}/{controller}/{action}", new { country = UrlParameter.Optional, language = UrlParameter.Optional, controller = "Home", action = "Index" }, new { country = COUNTRY_REGEX, language = LANGUAGE_REGEX });
Is it simply not possible because my options are at the beginning of the route, or did I just miss something? I cannot find any documentation to tell me what I am doing is impossible or to point me in the right direction.
asp.net-mvc asp.net-mvc-routing
David m
source share