0

I found a specific situation where we don't set the thread culture after a page loads.

We also have a very rare case where someone's culture switches for no obvious reason.

Are these two things related?

I understand that when you use a thread pool, not everything gets reset in the pool. Is the thread culture one of these things and therefore could one person's culture whose thread has been given back to the pool be leaking into the next person's thread?

Chris Simpson
  • 7,821
  • 10
  • 48
  • 68
  • It's probably a bad idea. If I go to your website and get a japanese version randomly, I'm probably going to assume you're website is japanese only and leave to never return. – Earlz Dec 18 '12 at 22:19
  • 2
    Somewhat related question, with the advice in the answer not to count on the thread being reset: http://stackoverflow.com/questions/1467194/does-changing-the-culture-of-a-threadpool-thread-affect-it-when-it-gets-returne – Michiel van Oosterhout Dec 18 '12 at 22:25

1 Answers1

2

Given the info in the link in michielvoo's comment, I think it is very probable that those two things are related.

You might want to set the thread culture manually from the HTTP request header Accept-Language (in global.asax in Application_BeginRequest method override) and use a default fallback culture if that header is missing (depends on your web's target audience, but in general preferably use en).

However if possible, it is a very good practice to let the user/visitor override such culture/language settings - browsers are evil and sometimes the culture settings may be out of user's control (e.g. Internet cafe while on vacation in a country whose language the user does not speak)

Community
  • 1
  • 1
Honza Brestan
  • 10,637
  • 2
  • 32
  • 43
  • 1
    The case which meant that this value was not set has already been fixed I was just interested in if anyone knew for certain that the thread culture would not be reset for each page load. We have a number of rules that determine the culture not just the browser header. I believe overriding InitializeCulture (which is what we do) is preferable to changing Application_BeginRequest. – Chris Simpson Dec 18 '12 at 23:13
  • In that case the only part relevant to you is michielvoo's link. Also you may be right, for .aspx the InitializeCulture is probably preferred, if it is somehow centralized, e.g. in a master page. – Honza Brestan Dec 18 '12 at 23:19
  • Yeah, we override System.Web.UI.Page page partly for that purpose. – Chris Simpson Dec 19 '12 at 01:10