.NET 全球化:在页面或线程上设置 Culture/UICulture?有什么区别?
问题标题基本上是整个问题。在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两种方法最终都会设置当前线程的属性。
最大的区别是
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, theThread
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 aCultureInfo
instance myself.