Search code examples
c#asp.net-2.0culture

How do I detect the current culture of the executing thread?


I have a nice function setup for formatting dates as per Leading Zero Date Format C#

But it turns out in our farm we have some blades running on a UK locale and some on a US locale so depending on which it crashes.

So what I'm after is how do I test the current server locale?

Something like...

if(Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "GB"){
...

}
else
{

..otherstatement
}

Ta


Solution

  • You should pass in the desired culture to all of your formatting functions (InvariantCulture, usually).

    Alternatively, you can set the culture on the page like so. That code could also go in the Application BeginRequest override in your asax.cs file in order to affect all pages.