I am creating a website that will support multiple languages.
I also wanted to localize the url so that it works like this:
- www.domain.com/en/contact
- www.domain.com/de/kontakt
For this, I decided to use different controllers for each language.
I also added a code that stores your preferred language in a cookie.
If the same user visits www.domain.com , I would like the code to check this cookie and then redirect the visitor to the index page with the appropriate language.
To achieve this, I have this code in global.asax for the route
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "en", action = "LanguageRedirect", id = UrlParameter.Optional }
And then in the ru controller there is a LanguageRedirect method:
public ActionResult LanguageRedirect() { string cultureName=""; HttpCookie cultureCookie = Request.Cookies["_culture"]; if (cultureCookie != null) { cultureName = cultureCookie.Value; cultureName = cultureName.Substring(0, 2); } // Some custom code that checks valid languages if (!CultureHelper.isValidCulture(cultureName)) cultureName = "en"; return RedirectToAction("Index", cultureName); }
I'm not sure what the appropriate SEO redirect method should be? Should I use RedirectToAction or use RedirectToActionPermanent ?
source share