Asp.Net 3.5 explicit localization with web app
In an asp.net 3.5 application, I am trying to explicitly localize the text. Example from MSDN
<asp:Label ID="Label2" Runat="server" Text="<%$ Resources:LocalizedText, Msg1 %>">
The problem is that it cannot find the resource class. I am using an asp.net application, not a website. I tried to specify the full namespace for the resource class. eg:
<asp:Label ID="Label2" Runat="server" Text="<%$ Resources:MyProject.Web.Properties.Resources, Msg1 %>">
But to no avail. Any ideas?
Forgot to mention ... if I use an expression for data binding like this, it works:
<asp:Label ID="Label2" Runat="server" Text="<% MyProject.Web.Properties.Resources.Msg1 %>">
Update:
After spending a little time with the reflector, he came across this in the 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;
}
So it looks like it is expecting the Resource.xxx namespace. My current resource file is located in WebApp> Properties> Resources with the web application namespace. Think this is a problem.
source to share
I need to work with this:
<asp:Localize runat="server" Text="<%$ Resources:PageResource1.Title %>" />
My resource is located in a folder App_LocalResources
in a file named PageName.aspx.resx
. My resource key name PageResource1.Title
.
For global resource ( App_GlobalResource\ErrorMessages.resx
), this seemed to work:
<%$ Resources:ErrorMessages, ErrorHasOccurred %>
source to share