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;
}
}
Hi David,
try to get the user's language by accessing the CultureInfo object of the current thread:
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
is working on a reply...