views:

18

answers:

1

I'm considering the use of the 'globalization' web.config section in our ASP .NET application to provide a default culture to be applied to all requests. In some cases, we'll be overriding this value programmaticly during the 'AcquireRequestState' event, but I'd like to know at what stage in the request life cycle the 'culture' and 'uiCulture' properties of the 'globalization' section will be applied to the thread servicing the request.

I'm assuming that there's some code in the System.Web namespace that looks like this:

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(webConfigCulture);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(webConfigUiCulture);

Where 'webConfigCulture' and 'webConfigUiCulture' represent the values of the 'culture' and 'uiCulture' in the globalization section of the web.config.

Anyone know where this is happening (e.g. what request/page event)? Or am I way off base?

+1  A: 

Altually, the culture is stored in the http context rather than the thread, and copied from there to the thread. A request can be moved from one thread to another over the page cycle, so the culture has to follow the request, not the thread.

So, the culture is applied when the http context object is created, which happens at "Start" stage of the page cycle, before the PreInit event.

You can read more here: ASP.NET Page Life Cycle Overview

Guffa
Thanks for the info. Under what circumstances would a request span more than one thread (other than having some code explicitly spin up a separate worker thread to do some work)? If I need to programmatically override the culture set in web.config should I not simply be attaching a new cultureInfo to the current thread?
Jesse Taber
@Jesse Taber: If the request is waiting for some resource (database, file, et.c.) the thread may start handling another request, and when the result arrives the request may be continued by a different thread. It doesn't matter where you set the culture, it's actually only stored in one place, so it will be set correctly.
Guffa