Home > Development > Local Resources vs Global Resources in .NET

Local Resources vs Global Resources in .NET

January 27, 2010 Leave a comment Go to comments

The idea here is to build a multi-language web application using ASP.NET MVC 1.0. It is known that since .NET 2.0 it is already coming with a good technique for globalization and localization for its .aspx pages, .ascx files, and string in the code behind; by adding App_GlobalResources and App_LocalResources folders and add to these folders a resources files (.resx).

Local Resources vs. Global Resources:

Local resource files are located in App_LocalResources folder and accessed only by the pages it is assigned to, and it can be implicitly accessed by the asp server controls properties as following:

<asp:Label ID="Label1" runat="server" Text="Label" meta:resourcekey="Label1"></asp:Label>

This meta:resourcekey attributes till the server control to grab it is details strings from the page resource file implicitly which should have the following name convention

<pagename>.aspx.[<language>-<culture>].resx

and for default language file which used for fallback

<pagename>.aspx.resx

These files can have entry for each server control’s attribute (Label1.Text,Label1.ToolTip, etc…).

Global resource files are located in App_GlobalResources folder and it is accessed by any code in the web application, the file name does not have any strict convention – except for the .resx extension of course –, and also ASP.NET generates a strongly typed object that gives you a simple way to access programmatically the global resources.

Resources.<resource file name>.<resource item key>

you can use any combination of global and local resources, global resources are mainly used for shared resources between pages, and to access strongly typed resources programmatically.

The downsides I faced are those resources are not accessed within other project in the solution other than the web application project, and also in ASP.NET MVC it is not recommended to use server side controls so we do not buy anything from the implicit resources binding.

I will elaborate on a solution for ASP.NET MVC based application in this post.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.