From where CultureInfo.CurrentCulture reads culture
Asked Answered
C

4

8

I want to know the setting or location from where System.Globalization.CultureInfo.CurrentCulture reads its value.

I am using a windows 7 laptop and have changed my system's regional and date-time settings to US.

I got my code working using below setting in web.config under

<globalization culture="en-US" />

Thanks

Crews answered 14/3, 2012 at 7:31 Comment(0)
C
9

the MSDN says

The culture is a property of the executing thread. This read-only property is equivalent to retrieving the CultureInfo object returned by the Thread.CurrentCulture property. When a thread is started, its culture is initially determined by calling the Windows GetUserDefaultLocaleName function.

In other words, it's based on the Thread, witch has a context... in the ASP.NET context, that comes from the Locale used in the client Browser first if using Server Variables or the System Settings on everything else.

Under this Web context you can get it using the Server.Variables method on HTTP_ACCEPT_LANGUAGE and you will get something like:

en-US,en;q=0.8,pt-PT;q=0.6,pt;q=0.4

Witch states that the client browser has 3 languages set, where the first one is en-US.

Everything from System.Globalization comes from the System definitions just like the image below shows:

enter image description here

code above is:

<p>
    <pre>System.Globalization.CultureInfo.CurrentCulture</pre> 
    is @System.Globalization.CultureInfo.CurrentCulture.EnglishName
</p>

No matter what browser is in use, the definition for System.Globalization will always come from the Operating System definition

enter image description here

Cameraman answered 14/3, 2012 at 7:36 Comment(1)
Thanks Balexandre, this seems to be good info. But I just checked my browsers locale setting and its en-US(I am using firefox and I checked setting general.useragent.locale under about:config) also my systems datetime and regional settings were set to en-US. But still I get en-IN when checking System.Globalization.CultureInfo.CurrentCulture. Do you have any idea where I am wrong?Crews
O
5

After spending 8 hours -- Find out a solution Thanks to Ronald -- CultureInfo values differ between applications for the same culture. Is this a bug?

It turns out that regional settings are stored per user in Windows. This is something I should have been aware of. Updating the application pool to run as myself produced the same result across both applications.

To be fair, what is still confusing is how Network Service (the account the application pool was running under) came to have the incorrect value. I'm not even sure how I'd rectify that.

Edit:

If you need to update the regional settings for reserved accounts. You have two options.

Control Panel > Regional Settings > Click the administrative tab and then select "Copy Settings". 

On the screen that launches, ensure you check "Welcome Screen and system accounts". Older versions of Windows are similar I believe. For the brace. Registry: HKEY_USERS > SID... > Control Panel > International. The security identifier for Network Service is: SID: S-1-5-20.

Ensure you restart the application pool for settings to take effect.

I did #1 -- and it did a trick for me!

Orsino answered 16/9, 2013 at 15:6 Comment(0)
O
2

In case of ASP.NET, from

HKEY_USERS\S-1-5-20\Control Panel\International\

S-1-5-20 is the security identifier of the Network Service "user" (http://support.microsoft.com/kb/243330)

For other types of applications, refer to the documentation of GetUserDefaultLocaleName function (https://msdn.microsoft.com/en-us/library/windows/desktop/dd318136%28v=vs.85%29.aspx)

For an easy GUI way of changing the locale of S-1-5-20, see sitecorebasics's answer

Ordination answered 2/2, 2015 at 14:48 Comment(0)
T
1

It uses the windows GetUserDefaultLocaleName function.

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture.aspx

Trotta answered 14/3, 2012 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.