How to use app_GlobalResource or app_LocalResource?
Local Resources:
- Local resource is specific to a single Web page and used for providing versions of a Web page in different languages.
- Local resources must be stored in App_LocalResources sub folder.
- Local resources must be named in format [.language / language and culture].resx.
Ex: Default.aspx.resx- Base resource file. This is the default, or fallback, resource file.
Default.aspx.de.resx- A resource file for German etc.
Global Resources:
Global Resources Localization Suggestion for ASP.NET
- Global resource can be read from any page or code that is in the application.
Global resource must be stored in App_GlobalResources at the root of the application.
// Get the global resource string. try { globalresourcestring = (String)GetGlobalResourceObject("MyResource", "GlobalResourceString1"); } catch { globalresourcestring = "Could not find global resource."; }
These are the steps for ASP.NET MVC 5 Web Application
- Right-click the solution name.
- Add > Add ASP.Net Folder > App_LocalResources
- File should open. Add content. (Name/Value)
- Locate Access Modifier at the top of the .resx file and change it to Public and save the file.
- Right click the .resx file of choice and select properties.
- Change Build Action from content to embedded Resource.
- Open solution explorer and expand the Views folder.
- Open the web.config file.
- Add new namespace to the namespaces section.
ex.
<add namespace="ProjectName.App_LocalResources" />
In order to access the local resource file in your html code you must add
@using ProjectName.App_LocalResources
to the top of the page.
You can then access the different resources in the App_LocalResources by using the
@NameOfResxFile.NameOfValueInResxFile
I hope this helps.