0

I need to set a specific culture for every request in my MVC 3 app. (The culture is determined by the user's profile preference, or if none is set it falls back to a default by Area). If I set the Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture somewhere in the request pipeline, I am worried that it will either:

  1. Change threads (and therefore cultures) in the middle of the request
  2. Reuse the same thread later and maintain the wrong culture

Both of these seem reasonable based on info in this Q.

Community
  • 1
  • 1
just.another.programmer
  • 8,579
  • 8
  • 51
  • 90

1 Answers1

-1

You can use BeginRequest method of the HttpApplication in global asax file. Check this answer.

This will ensure every request will be correctly set up immediately than you shouldn't wory about thread reuse.

Community
  • 1
  • 1
Aik
  • 3,528
  • 3
  • 19
  • 20
  • The suggested solution works. Begin request method run as the first programically accessible point on the request thread than it is the good place to change culture of the thread. – Aik Aug 25 '14 at 11:29
  • As documented in the linked Q, a request can change threads in the middle of the request. If `BeginRequest` fires when the request is in one thread and then the request moves, what guarantee do I have that the culture will move with the request? – just.another.programmer Aug 25 '14 at 15:47
  • Request cannot change thread. Request is processed by one thread for whole live of the request. You can start many other working threads (you have to maintain thread culture manually for them in place where you create them) but the request is processed only in one thread. – Aik Aug 26 '14 at 13:15