2
在asp.net 3.5應用程序中,我試圖明確地本地化文本。以下示例來自MSDNAsp.Net 3.5使用web應用程序進行顯式定位
<asp:Label ID="Label2" Runat="server" Text="<%$ Resources:LocalizedText, Msg1 %>">
問題是它似乎無法找到資源類。我正在使用一個asp.net應用程序,而不是網站。我試過爲資源類指定完整的命名空間。例如:
<asp:Label ID="Label2" Runat="server" Text="<%$ Resources:MyProject.Web.Properties.Resources, Msg1 %>">
但無濟於事。有任何想法嗎?
忘了提...如果我使用數據綁定表達式這樣的,它的工作原理:
<asp:Label ID="Label2" Runat="server" Text="<% MyProject.Web.Properties.Resources.Msg1 %>">
更新:
花一點時間與反射後在ResourceExpressionBuilder碰到這樣的:
private static IResourceProvider GetGlobalResourceProvider(string classKey)
{
string str = "Resources." + classKey;
CacheInternal cacheInternal = HttpRuntime.CacheInternal;
string key = "A" + str;
IResourceProvider provider = cacheInternal[key] as IResourceProvider;
if (provider == null)
{
EnsureResourceProviderFactory();
provider = s_resourceProviderFactory.CreateGlobalResourceProvider(classKey);
cacheInternal.UtcInsert(key, provider);
}
return provider;
}
因此,它看起來像期待Resources.xxx的命名空間。我當前的資源文件駐留在Web應用程序的名稱空間中的WebApp> Properties> Resources中。認爲這是問題。