页面管道中改变文化的最后一点?
在 asp.net 页面加载管道中,我可以通过执行以下操作来更改页面区域性的最后一点是什么?
Thread.CurrentThread.CurrentCulture = << new culture >>;
Thread.CurrentThread.CurrentUICulture = << new culture >>;
我正在更改代码中的文化,并想知道在什么时候我可以更改页面文化,以便获取正确的资源文件等。
Page PreInit 在管道中是否太晚而无法改变文化?我知道 Page 类中有一个 InitialiseCulture 方法,但我正在该方法之外工作。
What is the last point in the asp.net page loading pipeline that I can change the culture of a page by doing the following?
Thread.CurrentThread.CurrentCulture = << new culture >>;
Thread.CurrentThread.CurrentUICulture = << new culture >>;
I am changing the culture in my code and want to know at what point is the last point in which I can change the pages culture so that the correct resource files etc are picked up.
Is the Page PreInit too late in the pipeline to change the culture? I am aware there is an InitialiseCulture method in the Page class but I am working outside of this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 MSDN 文档,正确的方法是使用
InitialiseCulture
- 它在页面生命周期的早期就被调用,甚至在创建控件之前。这甚至发生在PreInit
事件之前。据说,人们早在
Page_Load
事件时就设置了文化信息。例如,请参阅此知识库文章或此代码项目文章。所以我想 PreInit 事件应该没问题。有两个相关属性 - Culture 和 UICulture。 AFAIK,UICulture 用于加载正确的本地(特定于页面)/全局资源,这将在渲染阶段完成 - 所以不应该成为问题。来自线程的区域性信息被许多框架方法使用,在页面生命周期中设置区域性之前,您需要小心使用任何依赖于区域性信息的代码 - 此类代码的示例可以是数据格式化或从请求解析数据等
As per MSDN documentation, correct way is to use
InitialiseCulture
- it gets called very early in page life-cycle before even controls are created. And that is even beforePreInit
event.Said that, people have set the culture information as late as
Page_Load
event. For example, see this KB article or this code project article. So I guess that PreInit event should be ok.There are two relevant properties - Culture and UICulture. AFAIK, UICulture is used for loading correct local (page specific)/global resources and that would be done at rendering stage - so should not be an issue. The culture info from thread get used by many frameworks methods and you need to be careful using any code that is dependent on the culture information before you sets the culture in page life cycle - example of such code can be formatting of data or parsing from request data etc.
也请参阅我对您原始帖子的评论。
http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
See my comment to your original post too.
http://msdn.microsoft.com/en-us/library/bz9tc508.aspx