Regional Settings en-GB CultureInfo.CurrentCulture.Name = en-US

M

magister

Hello,

I know I can set the Culture to what I want, but shouldn't the current
culture be taken from the regional settings on the web server's
control panel!!!

Mine is set to "united kingdom"

but in my asp.net page I do

string cl = CultureInfo.CurrentUICulture.Name;
string cn = CultureInfo.CurrentCulture.Name;

both string return en-US

I need this to be en-GB so my comparevalidator will do a date check on
a textbox....

Anyone else experience this?
 
N

Nicole Calinoiu

What is the Windows regional setting for the user context in which the
server-side code is executing? I'm guessing that it's not the same account
under which you're viewing the regional settings since the latter is
probably the administrator account.
 
T

Ted Harper

I know I can set the Culture to what I want, but shouldn't the current
culture be taken from the regional settings on the web server's
control panel!!!

I'm not sure exactly what you want, but what we do (in Page_Load()) in
our ASP.Net applications - which I believe will give the effect you
want - is this call to a routine we wrote specifically to enable easy
multi-language/multi-date-format/etc:

UIUtilities.setCulture(Request);

Where this is what gets called:

/// <summary>
/// Set the display culture for the current thread to the most
appropriate culture from the user's incoming Http "request" object.
/// </summary>
/// <param name="request"></param>
internal static void setCulture(HttpRequest request)
{
if (request != null)
{
if (request.UserLanguages != null)
{
if (request.UserLanguages.Length > -1)
{
string cultureName =
request.UserLanguages[0];
UIUtilities.setCulture(cultureName);
}
}
// TODO: Set to a (system-wide, or possibly
user-specified) default culture if the browser didn't give us any
clues.
}
}

/// <summary>
/// Set the display culture for the current thread to a particular
named culture.
/// </summary>
/// <param name="cultureName">The name of the culture to be set for
the thread</param>
private static void setCulture(string cultureName)
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(cultureName);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(cultureName);
}


What this does is that the thread that processes the output (and
input) for that user for the page is AUTOMATICALLY set for the
appropriate culture (eg for date input/output) for that user. It uses
a header which is sent automatically by the browser (4.0 and later -
works fine with Firefox/Mozilla too), so the user of your ASP.Net
application doesn't have to separately select a language/culture
preference in the application.

NB: You can change this setting for testing (in IE for example) by
going to Tools/Internet Options/Languages, then adding the language
you want to test and moving it to be the first/top one.

Because it is per-user, rather than being based on a server setting,
it is a lot more flexible as far as being "world-ready".

FWIW we use the same browser header to work in with the
ResourceManager mechanism to provide other-language text in the output
web pages too, simply by doing the following after the call to set the
thread culture to the right one for the user:

ResourceManager resourceManager = new
ResourceManager("AppName.strings", typeof(SampleForm).Assembly);

(then using ctrl.Text = resourceManager.GetString("NameOfItem") as
normal)

The net effect of all this is that a user who wants dates the "right
way" around (I'm an Australian) for output and input validation will
have the page work that way, and someone who prefers MM/DD/YYYY will
in turn have that work for their input/output WITHOUT you having to do
anything hardwired in your code, or forcing users to select a
language/culture preference for your app in their logon details.

ted.h.
 
N

Nicole Calinoiu

Depends which user account is being used. Unless you're impersonating a
custom user, chances are you'll need to manually edit the registry since you
probably won't be able to run the regional settings control panel for, say,
the ASPNET user unless you've been mucking with its password.

That said, I wouldn't recommend using this approach. It's a much better
idea to programmatically set the appropriate culture rather than relying on
the configuration of the web server or the runtime user context. Either of
these might be altered at any time to support some other application's
dependency. Also, you might find yourself needing to support the client
regional preferences, in which case programmatic setting is the only way to
go.

HTH,
Nicole
 
T

Ted Harper

Where can I check&change the regional settings of my user account?

You (probably) don't want to change the regional settings of "your"
user account, or even the ASPNET account on the server, but rather you
want to change them on the _thread_ doing the work on the ASP.Net
server to the regional settings of the CALLING users.

I posted a larger code fragmenet for you to do this in my other post
in this thread (which may not have propagated to you yet), but here is
basically what you do in Page_Load():

string cultureName = request.UserLanguages[0];
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(cultureName);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);

Once you have done that (up the top of Page_Load(),
DateTime.ToString() and DateTime.Parse() will operate with respect of
the culture settings of each calling user.

This operates using a standard browser header that is sent by 4.0 and
later browsers and indicates the language/culture preference of the
user. You can change the settings your browser sends for testing
purposes via Tools/Internet Options/Languages - add the language you
want and move it to the top/first position, then refresh the page you
are testing against (assuming it has implemented the logic above in
its Page_Load()), and you'll see the input/output formats change
appropriately.


ted.h.
 
B

bb

hello, im experiencing exatly the same problem, and suspect the answer
is something along the lines of what someone has linked to this message.

im now trying to find out how and where to set the locale settings for
whomever is owning the iis process (LocalSystem)


Hello,

I know I can set the Culture to what I want, but shouldn't the current
culture be taken from the regional settings on the web server's
control panel!!!

Mine is set to "united kingdom"

but in my asp.net page I do

string cl = CultureInfo.CurrentUICulture.Name;
string cn = CultureInfo.CurrentCulture.Name;

both string return en-US

I need this to be en-GB so my comparevalidator will do a date check on
a textbox....

Anyone else experience this?


--
 
B

bb

magister said:
Hello,

I know I can set the Culture to what I want, but shouldn't the current
culture be taken from the regional settings on the web server's
control panel!!!

Mine is set to "united kingdom"

but in my asp.net page I do

string cl = CultureInfo.CurrentUICulture.Name;
string cn = CultureInfo.CurrentCulture.Name;

both string return en-US

I need this to be en-GB so my comparevalidator will do a date check on
a textbox....

Anyone else experience this?


Fixed this.

its something along the lines of this thread here ....
http://www.mcse.ms/message872783.html

i played around with what it suggested, but it didnt work, so instead, i
just looked through the HKEY_USERS registry entries looking at each's
control panel/international settings.

when i found one that had US rather than UK, i modified it, restarted
iis then requested my dummy page which outputs the locale.

eventually i found the right entry (which in my case was user S-1-5-20
which i guess corresponds with either the ASPNET user or the
IUSER_MACHINENAME account )

dont forget to restart iis after each change.




--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top