I've added the following code to my master template in order to redirect first time users to the correct language site and it works fine from all computers I've tried, but my customer says they're getting redirected to the wrong site (which is the fallback default site).
<script Language="C#" runat="server">
protected void Page_Load(object sender, EventArgs e) {
if(Request.UserLanguages != null && Request.ServerVariables["script_name"] == "/") {
string language = Request.UserLanguages[0];
if(!string.IsNullOrEmpty(language)) {
//Get the culture name - and make sure it's in the RFC 1766 standard <languagecode2>-<country/regioncode2>
//i.e. en-GB, so it's easier to check for
if (language.Length < 3)
language += "-" + language.ToUpper();
//Redirect to the correct page based on language, default to english
switch(language) {
case "en-US":
Response.Redirect("/en/");
break;
case "nb-NO":
Response.Redirect("/no/");
break;
case "nn-NO":
Response.Redirect("/no/");
break;
default:
Response.Redirect("/en/");
break;
}
}
}
}
</script>
Anyone knows what can cause this? Any help appreciated... ;)
You could do that. But I would guess that people setting their browser to a specific language does not want to be overruled (I certaintly don't like that) so I'm not sure that you should.. :-)
I'm also looking for a system which redirects the user to the correct language. For example English should go to www.sample.com and Chinese should go to www.sample.cn. The host names are already set correctly on the start nodes. Is the above sample (first post) the best way to do this or are there better solutions. For example based on IP address?
I implemented the above script in my master template, but for some reason it's not working. Do I have have to configure something else besides this script?
Language
I've added the following code to my master template in order to redirect first time users to the correct language site and it works fine from all computers I've tried, but my customer says they're getting redirected to the wrong site (which is the fallback default site).
Anyone knows what can cause this? Any help appreciated... ;)
Sorry about the non-specific title. Tried to correct it, but only got an error upon submitting the correction...
Looks like they've set their browser culture to something other than en-US, nb-NO or nn-NO.. Try logging Request.UserLanguages.
Thanks Sebastiaan,
I added no-NO for Internet Explorer and that seemed to help a bit at least.
Any other way to do this? Geo IP Address Lookup?
You could do that. But I would guess that people setting their browser to a specific language does not want to be overruled (I certaintly don't like that) so I'm not sure that you should.. :-)
Hello,
I'm also looking for a system which redirects the user to the correct language. For example English should go to www.sample.com and Chinese should go to www.sample.cn. The host names are already set correctly on the start nodes. Is the above sample (first post) the best way to do this or are there better solutions. For example based on IP address?
Jeroen
I implemented the above script in my master template, but for some reason it's not working. Do I have have to configure something else besides this script?
thanks for your help,
Anthony Candaele
Belgium
is working on a reply...