.NET Globalization: Set Culture/UICulture on a Page or a Thread? What's the difference?
-
30-09-2019 - |
Pergunta
Question title is basically the entire question. In ASP.NET you can set the Culture/UICulture properties of a page by overriding the InitializeCulture method, or you can set the properties of the current thread.
What are the differences? What are the advantages/disadvantages of both? What situations would you use each option?
Solução
Both approaches ultimately set the properties on the current thread.
The biggest difference is that the Page
methods support automatic language detection - they can determine the language from the request (if you set the value to "auto", optionally with a default). By contrast, the Thread
methods require a specific culture instance.
For a web application, I'd just use the Page
methods, because they provide additional options and save me the (admittedly trivial) trouble of constructing a CultureInfo
instance myself.