I’m trying to implement localization with routes
I have the following:
routes.MapRoute( 'DefaultLocalized', '{lang}/{controller}/{action}/{id}', new { controller = 'Home', action = 'Index', id = '', lang = 'en' } ); routes.MapRoute( 'Default', '{controller}/{action}/{id}', new { controller = 'Home', action = 'Index', id = '' } );
When I call my page domain/en/home/index, it works fine but when i call domain/home/index I get error 404: resource cannot be found.
Also when I’m at domain/en/home/index and I click a secured page I get redirected to domain/Account/login how can I be redirected to domain/en/Account/login?
Also when I get an application error how can I be redirected to domain/en/home/error?
The real question is how can I implement localization with language as a route parameter?
You could also introduce a constraint even tighter than Marc Gravell and Freddy Rios.
something like ‘en|de|fr|es’. This would mean hardcoding the languages but usually these are few and known.