I have got following routing, which basically enables me to keep the language within the url and makes sure only de and fr (constraint) is possible. In the Default – Routing, I set de as standard if there is no language in the url contained:
// Routing with language
routes.MapRoute("Default_with_language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|fr" });
// Standard-Routing
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "de",
});
How can I change the default-language in each request? Let’s say I have two Urls, one in german and one in french, I would like to have lang = "fr" if the french url is called…
Thx for any tipp
sl3dg3
In your
Application_BeginRequesthandler, you can access the current route and you should be able to change the values using something like this.Hopefully, that’s enough to make routing pick up the new value.