Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Thread.CurrentThread.CurrentCulture.Name showing "en-US" when my server's regional language is set to English (United Kingdom)

I have a Web Application which at various points makes users enter dates and also displays dates to users. When debugging (and when the site is running on our test and staging servers) the date formats appear in dd/mm/yyyy format (when using DateTime.ToShortDateString()). These servers (and my dev environment have "English (United Kingdom)" set as the language under the windows regional options. All good so far. However, on the live server dates appear in the format mm/dd/yyyy even though the live server still has the language set to "English (United Kindgom)". I've seen this question which explains how to parse the date in a specific format and I already know how to get the date in the required string format (DateTime.ToString("dd/MM/yyyy")) but am wondering what other OS setting on the live server is causing this discrepancy? I've also seen this question, but it doesn't seem to answer my question.

Some additional information: on the dev, test and staging environments System.Threading.Thread.CurrentThread.CurrentUICulture.Name="en-US" System.Threading.Thread.CurrentThread.CurrentCulture.Name="en-GB"

And on the live environment System.Threading.Thread.CurrentThread.CurrentUICulture.Name="en-US" System.Threading.Thread.CurrentThread.CurrentCulture.Name="en-US"

like image 418
Matthew Dresser Avatar asked May 19 '11 09:05

Matthew Dresser


2 Answers

Have you checked the globalization section of web.config?

You can set it declaratively like so:

    <globalization uiCulture="en-GB" culture="en-GB" />

See: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

like image 66
James McCormack Avatar answered Oct 30 '22 14:10

James McCormack


Regional Settings apply on a per-user basis - so you need to ensure that you change the regional settings for whichever user IIS is running your application under, e.g. Network Service.

Looks like many others have searched for ways to do this (google "IIS change regional settings"). It looks like most people achieve it by hacking the settings into the appropriate part of the registry (under HKEY_USERS\IUSR-SID\Control Panel\International)

like image 34
Damien_The_Unbeliever Avatar answered Oct 30 '22 14:10

Damien_The_Unbeliever