MVC 2 multilanguage in URL
I'm building a multilanguage application with MVC 2. I read a lot of posts about different way开发者_StackOverflow社区s to get the user's language. I think the best way to save the language, is to put it into the URL like this: www.example.de/language/controller/view.
My questions: 1. how should global.asax.cs look? I tried it to setting something below but it did not work:
routes.MapRoute("Default with language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|en" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "en",
});
There was a "en" for example in the route, but it always did not take the Resourse.en, it only took the default.
- Question: How to get the current language in the controller?
- Question: How to change the language?
Maybe this can help?
MVC Localization route
精彩评论