views:

135

answers:

3

I know I can set a CultureInfo object with an specified culture in the Application_BeginRequest event as is described here, but I don't want to do it for each request but in the application startup.

All I can imagine is that I can use the Application_Start event, but I don't know how to set the global culture.

+1  A: 

Thread.CurrentThread.CurrentUICulture

Keep in mind, this is overriding the settings that the WinForm app will have gotten from the computer. For example, if the user has a custom date format defined, this will replace that.

Serapth
+2  A: 

Set it in your web.config:

<globalization uiCulture="es" culture="es-MX" />

More info here: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

chaiwalla
+1  A: 

gattaca's answer is right, but if you want to really dynamically change the cultureinfo based on use's preference or browser's language setting, the best place is override Page class' InitializeCulture method. So you can write a base class to this.

protected override void InitializeCulture() {

LanguageHelper.RestoreUserLangugagePreferrenceIfAvailabe();

}

Of course this seems to over kill, because you need the change the base class. There are other place to put at, like using a module to inject your code, but I try all those solutions, page_load event, but they all do not work 100% with .net localization architecture. Try the localresource file, global resource file, and you will see what I mean.

Fred Yang