.NET Globalization: Set Culture/UICulture on a Page or a Thread? What's the difference?
Asked Answered
O

1

1

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?

Oxalate answered 14/10, 2010 at 13:0 Comment(1)
There you go: support.microsoft.com/kb/306162Openfaced
C
3

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.

Clara answered 14/10, 2010 at 13:17 Comment(2)
Brilliant, that makes sense. One quick followup though.. how is the language detected from the request?Oxalate
It accesses it through HttpRequest.UserLanguages, which parses the request's HTTP headers. (I think the Accept-Language header, maybe Content-Language.)Clara

© 2022 - 2024 — McMap. All rights reserved.