Copied to clipboard

Flag this post as spam?

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


  • David 7 posts 27 karma points
    Aug 13, 2010 @ 17:44
    David
    0

    Redirecting by getting the Language of the Browser with a .NET Control

    I try to redirect the page with a -NET Control but i didn't work. Can anybody halp me?

     

    protected void Page_Load(object sender, EventArgs e)
            {
                redirectUrl();
            }


            public String GetLanguageOfBrowser()
            {
                #region WebSprachErkennung

                String strLanguage = String.Empty;

                // Sprache den Client Browser erkennen
                if (Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"] != null)
                {
                    strLanguage = Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
                   
                    strLanguage = strLanguage.ToLower();
                   
                }
                else
                {
                    strLanguage = "de";
                }
                    Session["MemberLanguage"] = strLanguage;

                return strLanguage;
                   
                #endregion // WebSprachErkennung
               
            }

            public void redirectUrl()
            {
                String ch_de_URL = "http://www.website.ch/1.aspx";
                String ch_fr_URL = "http://www.website.ch/2.aspx";
                String ch_it_URL = "http://www.website.ch/3.aspx";
                String ch_en_URL = "http://www.website.ch/4.aspx";


                // Select
                switch (GetLanguageOfBrowser())
                {
                    case "ch-de":
                        Response.Redirect(ch_de_URL);
                        break;
                    case "ch-fr":
                        Response.Redirect(ch_fr_URL);
                        break;
                    case "ch-it":
                        Response.Redirect(ch_it_URL);
                        break;
                    case "ch-en":
                        Response.Redirect(ch_en_URL);
                        break;
                    case "en":
                        Response.Redirect(ch_en_URL);
                        break;
                    default:
                        Response.Redirect(ch_en_URL);
                        break;
                }

     

            }

     

     

  • Sascha Wolter 615 posts 1101 karma points
    Aug 13, 2010 @ 18:48
    Sascha Wolter
    0

    Hi David,

    try to get the user's language by accessing the CultureInfo object of the current thread:

    CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;

    The CultureInfo contains then the information you need. Be aware of the distinction between culture and UI culture though. You can read more about it here:
    http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx

    Hope that helps,
    Sascha

     

Please Sign in or register to post replies

Write your reply to:

Draft