1

Say I have a ASP.Net MVC 4 web application. In this app I have 2 controllers "Product" and "Support".

This app is a language-aware web app, so when a user navigates to http://server/product/index, I'd like to automatically redirect to http://server/en-us/product/index

Same thing for support: From http://server/support/ to http://server/en-us/support/

I already have some logic to determine the user's language based on the browser, I'm just not sure the best way to achieve that thing explained above.

Just to clarify, I already a default route with language

private const string languagePartPattern = @"(\w{2})|(\w{2}-\w{2,4})";

routes.MapRoute(
    name: "DefaultLang",
    url: "{lang}/{controller}/{action}/{id}",
    constraints: new { lang = languagePartPattern },   //For example: en or en-US
    defaults: new { lang = SettingsHelper.DefaultLanguage, controller = "EntryPoint", action = "Index", id = UrlParameter.Optional }
);

If I navigate to http://server/product/, it does not automatically redirect to http://server/en-us/product/. However, it works fine if I navigate to http://server/en-us/product/ directly

7
  • There are tons of articles, blogs and SO questions about this topic. Use the Google (or Bing ;-). Commented Jun 1, 2016 at 5:53
  • 3
    E.g. this or this or this. Commented Jun 1, 2016 at 5:54
  • 3
    I did search -> I Bing'ed ;-) and implemented a default route with url: "{lang}/{controller}/{action}/{id}", but if I navigate to server/product it does not redirect to server/en-us/product. It works fine if I navigate directly to server/en-us/product though. Commented Jun 1, 2016 at 6:15
  • 1
    See Language-specific Default URL using MVC's Attribute Routing and RouteLocalization.mvc for an example that includes redirecting to the current culture based on the user's browser settings (or any firewalls that happen to change the header - always give your users a way to select culture!!) Commented Jun 1, 2016 at 6:42
  • See this post Commented Jun 1, 2016 at 6:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.