页面管道中改变文化的最后一点?

发布于 2024-11-08 00:41:21 字数 359 浏览 4 评论 0原文

在 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 技术交流群。

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

发布评论

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

评论(2

束缚m 2024-11-15 00:41:21

根据 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 before PreInit 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.

朮生 2024-11-15 00:41:21

也请参阅我对您原始帖子的评论。

protected override void InitializeCulture()
{
    UICulture = "en";
    Culture   = "en-US";
}

http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

See my comment to your original post too.

protected override void InitializeCulture()
{
    UICulture = "en";
    Culture   = "en-US";
}

http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

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