views:

74

answers:

2

If I set Thread Culture and UICulture for one ASPX, after pass for that page, all my aspx that use the same thread(not same request) will have the same Culture?

Because I need to set Culture just for one ASMX

A: 

If the culture you set is not read from the browser settings (like it lives in a database) You need to set this on every request.

As described here: http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

Override the page's 'InitializeCulture' method on every page. A common base class for all your pages comes in really handy here.

I would suggest firing up .NET reflector and see what the default implementation does. It will help clarify what is going on by default.

As this is event is handled on the page level, and not in the Global.asax, I would expect this is re-set. also, as the article describes, this event is Called so early in the page life cycle that capturing User Input requires directly accessing 'Request.Form'.

EDIT: Please try this and See that this must be set in every request. Let me know if you see different results or if I misunderstand your question.

Default.aspx: prints '21.09.2010'

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="System.Globalization" %>

<script runat="server">
protected override void InitializeCulture()
        {
            UICulture = "de-DE";
            Culture = "de-DE";
            //base.InitializeCulture();
        }   
</script>
<HTML>
<head>
</head>
<body>
<%= System.DateTime.Now.ToShortDateString()%>
</body>
</HTML>

Default2.aspx: prints '9/21/2010' (my default cluture is es-US)

<%@ Page Language="C#" %>
<HTML>
<head>
</head>
<body>
<%= System.DateTime.Now.ToShortDateString()%>
</body>
</HTML>

The order in which you hit these pages does not matter. The results do not change.

One approach people is used is to store this info in a Session variable and use the Session Variables to set the culture ..so logic for this is centerlized.

brian chandley
A: 

I'm pretty sure that UICulture, once set, stays for the entire ASP session (which happens independently of whatever session you create for your own application).

Edit: looks like a straightforward summary here: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/localization.aspx

Oren Mazor
New requests you come with the same UICulture that I set on another request? Because I need to set Culture just for one ASMX
Fujiy
if the request is coming from the same client, and you haven't changed anything, then it should be the same UICulture.
Oren Mazor