Home All Groups Group Topic Archive Search About

Culture, Impersonation & Logon User?

Author
14 Jan 2007 11:25 PM
haroldsphsu
Hi all,

I apologize if I should post this to the asp.net group, but I have a
feeling this is a more general question.

I have the following ASP.Net test page on a German Windows 2003 server:

<%
Dim userCulture As System.Globalization.CultureInfo
userCulture =
System.Globalization.CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))

System.Threading.Thread.CurrentThread.CurrentCulture = userCulture
System.Threading.Thread.CurrentThread.CurrentUICulture = userCulture

Dim db as Double
db= (300/7)

%>
<html>
  <body>
    <div><%= System.Threading.Thread.CurrentPrincipal.Identity.Name
%></div>
    <div><%=
System.Threading.Thread.CurrentThread.CurrentCulture.DisplayName
%></div>
    <div><%=
System.Threading.Thread.CurrentThread.CurrentUICulture.DisplayName
%></div>
    <div>ToString() = <%= db.ToString() %></div>
    <div>ToString("en-US") = <%= db.ToString(New
System.Globalization.CultureInfo("en-US")) %></div>
  </body>
</html>

Environment:
- German Windows 2003 server.
- Virtual directory with anonymous access off and windows
authentication on.
- Web.config file has impersonation turned on.
- IE browser running on a different machine.

My problem is, if the user hitting the page (with English as the
preferred language) is also logged on to the server, I get the
following.  Notice the use of comma as the decimal separator on a
German machine:

English (United States)
English (United States)
ToString() = 42,8571428571429
ToString("en-US") = 42,8571428571429

I was expecting both numbers to use "dot" as the decimal separator
because:

1.  I've explicitly set the current thread culture to the preferred
region, which is en-US, and it is the case when I print out the display
name.
2.  I've passed the en-US CultureInfo object to the second ToString(),
which should presumably force it to display in the US format.  I've
checked the regional settings on the machine and "dot" is used as the
decimal separator for the US region.  This line does work as expected
if I pass in "New CultureInfo("en-US", False)", where False means I
don't want to use the user overridden configuration of the regional
settings.

Now, if the user hitting the page is not also logged on to the server,
I get what I expected:

English (United States)
English (United States)
ToString() = 42.8571428571429
ToString("en-US") = 42.8571428571429

So how does this work?  It appears that if the user is logged on to the
server, it doesn't matter what I set the current thread culture to be?
Any insight will be much appreciated!

Harold

AddThis Social Bookmark Button