Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 10, 2006 12:48 AM by rstrahl
Dec 07, 2006 07:02 AM|LINK
How can I detect the language of the browser, i want to select the language for the browser.
Dec 07, 2006 09:56 AM|LINK
HttpBrowserCapabilities bc = Request.Browser;
Response.Write("Supports VB Script = " + bc.VBScript + "<br>");
Response.Write("Supports Java Applets = " + bc.JavaApplets + "<br>");
Dec 07, 2006 10:03 AM|LINK
You could look at using the System.Globalization and CultureInfo, there is a write up here and some example code
Hope it helps
Dec 07, 2006 10:24 AM|LINK
ASP.NET 2.0 Support Auto Detection of Browser Language - you can determine the language of the requesting browser from user's culture.
Dec 10, 2006 12:48 AM|LINK
ASP.NET 2.0 has a couple of facilities to auto-detect locales and switch the thread's locale to the browser locale. Look for the <globalization> section in web.config (which is global obviously) or the Culture and UICulture attributes on the @Page directive.
You can also do this manually in your code by looking at Browser.UserLanguages which returns all the user's browser languages that are configured in her browser. Here's a routine I use in my most of applications to switch the culture and UICulture:
/// Sets a user's Locale based on the browser's Locale setting. If no setting
/// is provided the default Locale is used.
public static void SetUserLocale(string CurrencySymbol, bool SetUiCulture)
HttpRequest Request = HttpContext.Current.Request;
if (Request.UserLanguages == null)
string Lang = Request.UserLanguages;
if (Lang != null)
// *** Problems with Turkish Locale and upper/lower case
// *** DataRow/DataTable indexes
if (Lang.Length < 3)
Lang = Lang + "-" + Lang.ToUpper();
System.Globalization.CultureInfo Culture = new System.Globalization.CultureInfo(Lang);
if (CurrencySymbol != null && CurrencySymbol != "")
Culture.NumberFormat.CurrencySymbol = CurrencySymbol;
System.Threading.Thread.CurrentThread.CurrentCulture = Culture;
System.Threading.Thread.CurrentThread.CurrentUICulture = Culture;
I prefer doing this manually rather than letting ASP.NET's Auto features do this because typically you'll need to configure additional local settings like the currency symbol explicitly. If you do you need to create a new culture info anyway and so this
is a more consistent way to do it... You should call this soemwhere early in the ASP.NET lifecycle like Application_BeginRequest...
Hope this helps,
+++ Rick ---