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:43
    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;
                }

     

            }

     

     

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 14, 2010 @ 10:02
    Darren Ferguson
    0

    First off, please don't cross post the same question across forums.

    Your code looks fine to me, are you doing a Response.Write of the language to make sure it matches one of the clauses in your case statement?

    Also maybe do you redirect in the init method of the control rather than on load.

Please Sign in or register to post replies

Write your reply to:

Draft