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"];
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;
}
}
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.
is working on a reply...