Solved

.NET MVC (5) Localization based on URL

Posted on 2014-12-22
3
541 Views
Last Modified: 2014-12-22
I have an application in .NET MVC5 with 2 supported languages, English as default. I currently use cookies to switch between languages but would like to change the application to make use of URL's for specifying the language. I have found a solution that works, but the default language, English, must currently appear in the URL  ".../en/...".

How can I make use of URL for this purpose, while having the default (English) work without a culture (language) specified in the URL? English would be the default, when no culture (language) is specified in the URL and the second language would be accessible by including the culture (language) in the URL.
0
Comment
Question by:lynnwalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Michael74
ID: 40514115
How are you implementing the URL based language selection currently? If you are using RouteConfig have a look at this tutorial

http://www.codeproject.com/Articles/624180/Routing-Basics-in-ASP-NET-Web-API
0
 

Author Comment

by:lynnwalker
ID: 40514237
I am using RouteConfig, but in an MVC application, not Web API. Here is the current RouteConfig:

    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(name: "DefaultWithCulture"
                           , url: "{culture}/{controller}/{action}/{id}"
                           , defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                           , constraints: new { culture = "[a-z]{2}" }
            );

            routes.MapRoute(name: "Default"
                           , url: "{controller}/{action}/{id}"
                           , defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
0
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 40514250
In your default MapRoute set the culture you want as the default

routes.MapRoute(name: "Default"
                           , url: "{controller}/{action}/{id}"
                           , defaults: new { culture = "en", controller = "Home", action = "Index", id = UrlParameter.Optional }

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question