The CurrentCulture
and CurrentUICulture
does not automatically change according to what the browser reports. You will need to specify that:
protected override void OnInit(EventArgs e)
{
try
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
CultureInfo.GetCultureInfo(Request.UserLanguages[0]);
System.Threading.Thread.CurrentThread.CurrentCulture =
System.Threading.Thread.CurrentThread.CurrentUICulture;
}
catch (Exception ex)
{
// handle the exception
}
base.OnInit(e);
}
You should note that some of the languages that you can select ("en" for instance), will cause an exception when trying to assign it to Thread.CurrentCulture
, since it does not allow what is called "neutral" cultures. In short, a neutral culture is one that identifies only a language, but not geographical region. You can read more about that in the documentation for the CultureInfo
class.
Fredrik Mörk
2009-07-18 09:00:20