Different url depending of language/culture in ASP.net
In a site with multiple cultures support I intend to have the following routes:
routes.MapRoute(
"ProductsStartPage",
"{lang}/Products",
new { lang = defaultLanguage, controller = "Products", action = "Index" }
);
routes.MapRoute(
"ProductsCategoryPage",
"{lang}/Products/{category}",
new { lang = defaultLanguage, controller = "Products", action = "Category" }
);
routes.MapRoute(
"ProductPage",
"{lang}/Products/{category}/{product}",
new { lang = defaultLanguage, controller = "Products", action = "Product" }
);
A second language 开发者_开发百科would have Produkter instead of Products in the url.
How would I go on making this work without creating another MapRoute for each language/culture ?
I wouldn't be too scared of creating another route for each language.
The value for the controller in the route is essential. This is the value that you want to change, so you need a place where you keep the different values for each languages.
Then, when mapping the routes I would simply loop through the supported languages and call MapRoute for every language you support, and provide the localized value of the controller name.
Note that you need unique route names, so you should append or prepend the language name/code in your loop, so that you create routes with unique names.
精彩评论