DanP
DanP

Reputation: 6478

Determine CurrentCulture and CurrentUICulture for an arbitrary HttpContext

Given an instance of an HttpContext object, is there a way to determine the CurrentCulture and/or CurrentUICulture for the thread it is executing on? Or more generally, is there a way to gain access to the current thread under which it is running?

Upvotes: 1

Views: 1969

Answers (1)

Samuel Neff
Samuel Neff

Reputation: 74909

HttpContext has an internal property called DynamicCulture which you can read with reflection but it could change in the future. If this property is not populated, then the culture can be defined by the relevant Web.config or the Page.

If you're caching HttpContext objects and passing them between threads (probably a very bad idea anyways), then the most reliable way to also access the relevant culture is to wrap both the HttpContext and CurrentCulture into a custom class and pass that.

Upvotes: 1

Related Questions