使用ASP.NET前pression在资源文件没有被拾起 [英] Resource file not being picked up when using ASP.NET expression
问题描述
我想在ASP.NET Web窗体应用程序(.NET 4.0)使用资源文件。我使用VS2012。我有 App_GlobalResources文件
文件夹中的以下文件:
I'm trying to use resource files in an ASP.NET Web Forms application (.NET 4.0). I'm using VS2012. I have the following files inside the App_GlobalResources
folder:
-
Address.resx
(默认语言,英文) -
Address.ja-JP.resx
(日语)
Address.resx
(default language, English)Address.ja-JP.resx
(Japanese)
问题是,当我试图以显示日本在ASP.NET页面中的文本(* .aspx文件)。如果我使用下面的语法一切工作正常:
The problem is when I'm trying to display the text in Japanese in an ASP.NET page (*.aspx file). If I use the following syntax everything works fine:
<%= Resources.Address.Street1 %>
但是当我尝试将其绑定到一个 ASP的属性:标签
控制默认的文本(英文)显示,而不是日语:
But when I try to bind it to a property of an asp:Label
control the default text (English) is displayed instead of Japanese:
<asp:Label ID="lblStreet1" runat="server" Text='<%$ Resources:Address,Street1 %>'></asp:Label>
BTW文化正在会话变量设置,然后在母版页我有这样的事情:
BTW culture is being set in session variables and then in the master page I have something like this:
Thread.CurrentThread.CurrentCulture = (CultureInfo) Session["ci"];
Thread.CurrentThread.CurrentUICulture = (CultureInfo) Session["uci"];
另外,我不知道这是否是相关的或没有,但我所产生的 Address.ja-JP.resx
的Visual Studio(使用记事本++)之外再迁文件到 App_GlobalResources文件
夹和包含在溶液中的文件。
Also, I don't know if this is relevant or not but I generated the Address.ja-JP.resx
outside Visual Studio (using Notepad++) and then moved the file to the App_GlobalResources
folder and included the file in the solution.
我失去了一些东西在这里?
Am I missing something here?
推荐答案
我能够找到一个解决我的问题。在我的背后code只好重写<一个href=\"https://msdn.microsoft.com/en-us/library/system.web.ui.page.initializeculture%28v=vs.110%29.aspx\"相对=nofollow> InitializeCulture 方法,我做了这样的事情:
I was able to find a solution to my problem. In the code behind I had to override the InitializeCulture method, I did something like this:
protected override void InitializeCulture()
{
Thread.CurrentThread.CurrentCulture = (CultureInfo) Session["ci"];
Thread.CurrentThread.CurrentUICulture = (CultureInfo) Session["uci"];
base.InitializeCulture();
}
这篇关于使用ASP.NET前pression在资源文件没有被拾起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!