On Application_Start event, i implement change "en-AU" culture to "en-US" culture
var culture = new CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture.Name);
On Application_BeginRequest event, i implement check current culture but current culture is "en-AU"
Why is that? I have checked all event on global.asax that not have any proccess for change current culture. I am use MVC3 framework.
(all action only return view() without other proccess so they are not dangerous)
So, every thread have a System.Threading.Thread.CurrentThread. When a thread is implemented every time that it re-init System.Threading.Thread.CurrentThread with default value(en-AU), is'n that?
I have checked my mvc application, it have see two thread and every thread is implemented that every System.Threading.Thread.CurrentThread are init with default value(en-AU) whether i have changed System.Threading.Thread.CurrentThread to "en-US" last time.
I can change culture for every thread on Application_PreRequestHandlerExecute event, can't do?
void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
if (HttpContext.Current.Session != null)
{
string errorCode;
var culture = HttpContext.Current.Session["culture"] == null ? "en-US" : HttpContext.Current.Session["culture"].ToString();
var culture = new CultureInfo(nameCulture);
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
System.Threading.Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(culture.Name);
}
}
So, every thread have a System.Threading.Thread.CurrentThread. When a thread is implemented every time that it re-init System.Threading.Thread.CurrentThread with default value(en-AU), is'n that?
I don't see why every thread should inherit the setting you happen to set on one particular thread in the app_start code, so I don't think you will get what you're describing here.
I think setting it on each request is the better approach (like you're doing for Application_PreRequestHandlerExecute).
meoghe
Member
29 Points
74 Posts
Change current culture
Dec 18, 2012 02:05 AM|LINK
Herea is what i have done:
var culture = new CultureInfo("en-US"); System.Threading.Thread.CurrentThread.CurrentUICulture = culture; System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture.Name);Why is that? I have checked all event on global.asax that not have any proccess for change current culture. I am use MVC3 framework.
(all action only return view() without other proccess so they are not dangerous)
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: Change current culture
Dec 18, 2012 02:46 AM|LINK
Because that's a per-thread setting and there are many threads in a web server.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
CruzerB
Contributor
5399 Points
1098 Posts
Re: Change current culture
Dec 18, 2012 02:46 AM|LINK
Hi,
You have to implement the new culture at
http://msdn.microsoft.com/en-us/library/bz9tc508(v=vs.80).aspx
My Technical Blog
sameer_khanj...
Contributor
7066 Points
1381 Posts
Re: Change current culture
Dec 18, 2012 05:33 AM|LINK
Please read :-
http://support.microsoft.com/kb/306162
http://msdn.microsoft.com/en-us/library/bz9tc508(v=vs.100).aspx
http://odetocode.com/blogs/scott/
sameer.khanjit@gmail.com
View Blog
Click "Mark as Answer" on the post that helped you.
meoghe
Member
29 Points
74 Posts
Re: Change current culture
Dec 18, 2012 05:46 AM|LINK
So, every thread have a System.Threading.Thread.CurrentThread. When a thread is implemented every time that it re-init System.Threading.Thread.CurrentThread with default value(en-AU), is'n that?
I have checked my mvc application, it have see two thread and every thread is implemented that every System.Threading.Thread.CurrentThread are init with default value(en-AU) whether i have changed System.Threading.Thread.CurrentThread to "en-US" last time.
I can change culture for every thread on Application_PreRequestHandlerExecute event, can't do?
void Application_PreRequestHandlerExecute(Object sender, EventArgs e) { if (HttpContext.Current.Session != null) { string errorCode; var culture = HttpContext.Current.Session["culture"] == null ? "en-US" : HttpContext.Current.Session["culture"].ToString(); var culture = new CultureInfo(nameCulture); System.Threading.Thread.CurrentThread.CurrentUICulture = culture; System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture.Name); } }BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: Change current culture
Dec 18, 2012 02:18 PM|LINK
I don't see why every thread should inherit the setting you happen to set on one particular thread in the app_start code, so I don't think you will get what you're describing here.
I think setting it on each request is the better approach (like you're doing for Application_PreRequestHandlerExecute).
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/