Why does the variable Thread.CurrentThread.CurrentCulture change between page rendering and HttpModule.PostRequestHandlerExecute?

I am creating an HttpModule that needs to know the value of Thread.CurrentThread.CurrentCulture as set in the MVC application. This value is currently set by BaseController, but when my HttpModule.PostRequestHandlerExecute () method fires, it goes back to what it was before Culture before rendering the page.

I duplicated this by creating a simple web application with these steps:

  • Module.PreRequestHandlerExecute: set culture to A
  • Page_Load: The current culture A. Set the culture to B
  • Module.PostRequestHandlerExecute: The current thread culture is A. I expected it to be B, but it was changed between page rendering and PostRequestHandlerExecute

Any idea why .Net is changing this value or how can I get around it? The thread is the same, so something in .Net should explicitly return the culture.

+5
source share
1 answer

If you just set the culture for the working thread, any operation that causes the thread to switch (for example, another part of the page life cycle in asp.net) will return to the default culture.

Recommended approach here ...

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

This page discusses 3 options ...

  • Configure culture for the entire application.
  • Setting culture at the page level.
  • Setting culture programmatically for each request.

, , .

+2

All Articles