.NET 全球化:在页面或线程上设置 Culture/UICulture?有什么区别?

发布于 2024-09-27 19:03:05 字数 143 浏览 1 评论 0原文

问题标题基本上是整个问题。在 ASP.NET 中,您可以通过重写 InitializeCulture 方法来设置页面的 Culture/UICulture 属性,也可以设置当前线程的属性。

有什么区别?两者的优点/缺点是什么?您会在什么情况下使用每个选项?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀞厅☆埖开 2024-10-04 19:03:05

两种方法最终都会设置当前线程的属性。

最大的区别是 Page 方法支持自动语言检测 - 它们可以根据请求确定语言(如果将值设置为“auto”,可以选择默认值)。相比之下,Thread 方法需要特定的区域性实例。

对于 Web 应用程序,我只使用 Page 方法,因为它们提供了额外的选项,并且省去了我自己构建 CultureInfo 实例的(诚然微不足道的)麻烦。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文