I would like to create resource manager on my page and use some data stored in my resource files. (default.aspx.resx and default.aspx.en.resx)
The code looks like this:
System.Resources.ResourceManager myResourceManager = System.Resources.ResourceManager.CreateFileBasedResourceManager("resource",
Server.MapPath("App_LocalResources") + Path.DirectorySeparatorChar, null);
if (User.Identity.IsAuthenticated)
{
Welcome.Text = myResourceManager.GetString("LoggedInWelcomeText");
}
else
{
Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText");
}
but when i compile and run it on my local server i get this type of error:
Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: resource locationInfo: fileName: resource.resources Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the开发者_如何学编程 code.
Exception Details: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) on disk. baseName: resource locationInfo: fileName: resource.resources
Source Error:
Line 89: else Line 90: { Line 91: Welcome.Text = myResourceManager.GetString("LoggedOutWelcomeText"); Line 92: } Line 93:
can you please assist me with this issue?
Use GetLocalResourceObject() which is part of a System.Web.Page's base. If you wish to access global resources use GetGlobalResourceObject().
keep it simple ;-)
According to MSDN, CreateFileBasedResourceManager is expecting compiled resource files. Usually, one puts .resx files in App_LocalResources. Do you have files in this directory named resource.XXX.resources (where XXX is the current culture id) in this directory.
I don't have a VS handy in order to check this in an ASP.NET project, but the usual way to handle resource strings is to go the project properties, Resources tab and create strings there. This generates a strongly-typed wrapper around your resources, avoiding the need to explicitly create your own ResourceManager.
精彩评论