Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikolas van Etten 202 posts 162 karma points
    Sep 21, 2010 @ 21:31
    Nikolas van Etten
    0

    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).

    <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... ;)

  • Nikolas van Etten 202 posts 162 karma points
    Sep 21, 2010 @ 21:34
    Nikolas van Etten
    0

    Sorry about the non-specific title. Tried to correct it, but only got an error upon submitting the correction...

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Sep 21, 2010 @ 21:40
    Sebastiaan Janssen
    1

    Looks like they've set their browser culture to something other than en-US, nb-NO or nn-NO.. Try logging  Request.UserLanguages.

  • Nikolas van Etten 202 posts 162 karma points
    Sep 23, 2010 @ 00:00
    Nikolas van Etten
    0

    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?

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Sep 25, 2010 @ 19:30
    Sebastiaan Janssen
    0

    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.. :-)

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 01, 2011 @ 13:27
    Jeroen Breuer
    0

    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

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 08, 2011 @ 19:54
    Anthony Candaele
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft