Last post Mar 27, 2008 10:21 AM by s.sriram
Mar 24, 2008 10:29 AM|Juse71|LINK
Hi, I'm having a problem with a n-tier ASP.NET with italian and english language user interface.
In the UI layer, accordingly with the user decision, I override the InitializeCulture method to set the following:
All is fine in the UI layer and when execution passes to the business layer the setting is still ok, but when execution steps into the very first line of a method in the Data Access Layer the CurrentCulture and CurrentUICulture
are always set automatically to it-IT. And I saw that even the ManagedThreadId property changes.
I can't understand why, there is something that seems to reset language to it-IT, but just in the Data Access Layer....
This happens even if I don't setup anything in the web.config, and if I set my browser language to something different from italian.
What's the problem with the thread? How can I solve it?
Has anyone experienced something similar or can help as I'm stuck on this point?
UICulture Language Control Controls ASPNET
Mar 24, 2008 12:56 PM|F16I|LINK
I don't know whats the problem.
but I think that the DAL layer shouldn't know (anything) about the UI layer.
The UI layer should send that I want this language and it should get that.
Mar 26, 2008 08:27 AM|s.sriram|LINK
Once the user select his language and on some event (ie)button click or something, store the selected language from dropdown to a session variable.
HttpContext.Current.Session["Culture"] = ddlLanguage.SelectedItem.Value;
And add code below in Global.asax
//Code to be placed in Global.asax
protected void Application_AcquireRequestState(
object sender, EventArgs e)
protected void Application_AcquireRequestState(
string culture = System.Globalization.CultureInfo.CurrentCulture.Name;
if (HttpContext.Current.Session != null && HttpContext.Current.Session["Culture"] != null)
culture = Convert.ToString(HttpContext.Current.Session["Culture"]);
System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
The above code worked for me, i have master pages used in my application, and by this u can have users select their preferred language. The user selected language will be applied through out the application. Offcourse i assume u have the proper resource
file created for different language.
Hope this helps, Let me know if u still have any problem.
Mar 27, 2008 04:51 AM|Juse71|LINK
Great! Thank you very much!
I didn't know the Application_AcquireRequestState method.
So I guess you had experienced the same issue... still I can't undersand the reason the thread changed just inside the DAL layer.
This approach, I mean to retrieve the Thread.CurrentThread.CurrentCulture in each layer you need it, seems to be "lighter" rather than having to add the language as a parameter in each method, throughout all the layers. What do you think?
Thanks again :-)
Mar 27, 2008 07:01 AM|s.sriram|LINK
The above code which i wrote will make your application localizable.
That will pick the values from the resource files based on the language that the user selects. Your resources files will contain the corresponding values (For Example) If you have to support both German and English language, you will have
2 resource files one will be Sample.de.resx - for German and Sample.resx for English (assuming English as default). So your German resource file will have german values with some special characters, and your English resource file or the defult one contains
whenever user change the language, you will find all the controls like label's, button's Text are showing values from the resource file.
In your query u mentioned abt threads changed in DAL layer. what is need for changing thread in DAL layer?...
Hope i got yur query right. Please let me know if you have any issues.
Mar 27, 2008 08:01 AM|Juse71|LINK
The matter was that my multilingual terms are on an existing MySQL database, so I'm not using any of the ASP.NET resources, such as .resx files (which I know would be assolutely better!).
The problem I had encountered in this n-tier application was that the thread strangely got changed whenever the execution stepped into the DAL layer.
In fact, in my DAL code I didn't change the thread myself, I just used it to retrieve the culture like this:
String language = Thread.CurrentThread.CurrentCulture.ThreeLetterISOLanguageName;
Upon the value of this language variable then I query the MySQL database to get only the records which have value 'ITA' (or 'ENG').
Now with your code it is ok, it works fine!, the thread is forced to keep the value of the session variable.
By the way, do you know what the Application_AcquireRequestState method is meant for exactly? I noticed it is executed repeatedly during execution.
Mar 27, 2008 10:21 AM|s.sriram|LINK
Application_AcquireRequestState: Fired when the ASP.NET page framework gets the current state (Session state) related to the current request.