1

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.

3 Answers 3

2

Set it in your web.config:

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

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

1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.