【发布时间】:2011-08-18 12:56:29
【问题描述】:
我有两个页面 A 和 B。两者都应该使用适当的全局资源显示文本,具体取决于 Web.Conf 中的文化设置。
在Page A 上,我能够根据文化设置(因此在本例中为法语)可视化文本。
Page A 也有一个链接,它使用GetUrl 创建到Page B 的 URL(路由)
<asp:HyperLink
runat="server"
Text='<%# Eval("Title") %>'
NavigateUrl='<%# GetRouteUrl("TopicHub", new {TitleUrl = Eval("TitleUrl")}) %>'>
</asp:HyperLink>
在访问页面 B 时,我无法再看到法语文字,并且应用了英语文本(默认值)。 奇怪的事情是,如果我直接在浏览器中打开页面 B,文字会以法语显示。
所以我调试了 Global.asax.cs,我发现在单击使用 GetRouteUrl 创建的链接时,var Thread.CurrentThread.CurrentCulture 和 CurrentUICulture 是英文的,而不是我的 Web.Config 的法文。
我的问题是:
- 这可能是什么问题?也许是一个错误?
- 知道如何解决吗?
我的想法已经用完了,最后想到的是使用 Web.Conf 中的值在 Global.asax.cs 中强制 Thread.CurrentThread.CurrentCulture。
请让我知道您对此的看法。谢谢!
A页:
<asp:Literal ID="uxLatestGuides"
runat="server"
Text="<%$ Resources:Global, LatestGuides %>" />
B页:
<asp:Literal ID="uxLatestGuides"
runat="server"
Text="<%$ Resources:Global, LatestGuides %>" />
Global.asax.cs
protected void Application_BeginRequest(object sender, EventArgs e)
{
var check1 = Thread.CurrentThread.CurrentCulture;
var check2 = Thread.CurrentThread.CurrentUICulture;
}
Web.Config
<?xml version="1.0"?>
<configuration>
<system.web>
<pages enableViewState="false" theme="Cms-FE-00" >
</pages>
<globalization culture="fr" uiCulture="fr"/>
</system.web>
</configuration>
【问题讨论】: