Groups | Blog | Home
all groups > dotnet internationalization > february 2005 >

dotnet internationalization : Question about setting a culture


Poonam
2/16/2005 1:15:09 PM
Hi,
I am writing a .NET based web application which is localized also. I am
using Form Authentication and I use following code to transfer to the next
page:

FormsAuthentication.RedirectFromLoginPage(email, false);

Now on Session Start, I have following code:
protected void Session_Start(Object sender, EventArgs e)
{
// For each session request initialize the culture values with the
// user language as specified by url.

try
{
string culture = Request.Params.Get("lang");
if (culture == null)
{
culture = ConfigurationSettings.AppSettings["DefaultLanguage"];
}

try
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture
(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
}
catch(Exception)
{
// provide fallback for not supported languages. This is really just a
safety catch,
//for 'in-case' scenarios
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
}
}

So my first page shows me the right content based on the language but as
soon as they are redirected to the next page after authentication, my culture
value is set back to "English US".

I really appreciate if you guys can help me.

Thanks
Steven Cheng
2/17/2005 9:18:29 AM
Hi Poonam,

Welcome to msdn newsgroup.
Yes, the problem you mentioned is quite normal, the ASP.NET is a web
application which is request/respsonse based. So when a certain request is
processed, that worker thread is terminated or back to the threadpool, and
the sequential comming request may belong to a different thread. So only set
cultureInfo once in Session_Start is not a possible solution. We need to
adjust the thread's culture everytime at the beginning(in begin request
event for example). Maybe you can store the culture info in cookie, or just
create the culture from the clientside's browser 's prefered userlanguages.

HTH

thanks.

Steven

[quoted text, click to view]

AddThis Social Bookmark Button