Localization in ASP.Net

Localization

ASP.Net provides a technique to develop a multilingual web application. Such applications use same code-base but different language cultures. To accomplish this ASP.Net provides resource files. These files are with extension .resx, are local files which reside at server’s local machine. Depeneding upon the browser culture the web application picks up necessary resource file and display the text accordingly. Internally resources are stored in the form of key-value pair. User can have custom resources as well such as database, XML files etc.

Steps to demonstrate the Localization concept:
  • Create a web application using Visual Studio(I am using VS2005)
  • Add a new folder to the project solution App_localResources
  • Add a resource file to this folder say Default.aspx.resx ( it is a file with .resx extension)
  • Add a label on aspx page in design view.
  • Add a resource string with name value pair as label1.text as Welcome.
  • Add one more resource file say Default.aspx.es.resx and add it’s relative value. es stands for spanish, it’s universal standard.
    Go to the source view of aspx page and add meta:resourceKey=”label1” to the label
    The code will look like,
  • Go to the page directive of the page and add culture details as,Culture="auto:en-US" UICulture="auto"
  • Here auto keyword will detect the browser culture and will apply appropriate resource file to the page and en-US is default setting.
  • Now run the page in any browser, it will show the text depending upon the language it is configured to.
  • Try running this application by adding spanish language into the browser.
  • Here are the steps to change/add language to Internet Explorer.

Instrumentation

What is Instrumentation ?
It is a process which deals with logging and measuring all the things happening at application level.

Logging Events
There are some situations where a developer cannot predict if anything is going to fail in the application may be at developer end or a customer end. A developer must track such events through some mechanisms to ensure the smooth execution of an application. In order to do this .Net framework provides System.Diagnostics namespace to log events and debug application.

There are 3 default types of event logs as;
  1. Application
  2. Security
  3. System
User can create a custom event log, if required permissions are available for this user. 

Creating an Event log:
EventLog objEventLog = new EventLog("MyApplication");
objEventLog.Source="MyApplication";
objEventLog.WriteEntry("EventLog has been created", EventLogEntryType.Information);

Event sources are registered with windows registry. Hence to write into the event log fully trusted code is required. Partially or no trusted code can cause potential harm to the application as well as user's system .

Deleting an EventLog:
EventLog provides Delete method which removes all the logged events.
EventLog.Delete("MyApplication");

Reading entries from an EventLog:
EventLog stores each event in the form of an entry. EventLogEntry object represents single entry from an EventLog. Below is the code to demonstrate how to read EventLog;
EventLog objEventLog = new EventLog("MyApplication");
objEventLog.Source="MyApplication";
foreach (EventLogEntry objEventLogEntry in objEventLog.entries)
{
      console.WriteLine(objEventLogEntry.Source);
}







Labels

.net .Net Instrumentation logging .net localization Agile amazon amazon elasticache amazon services AppDomain Application Domain architecture asp ASP.Net authentication authentication mechanisms Byte order mark c# cache canvas app cdata certifications class classic mode cloud cloud computing cluster code-behind Combobox compilation Configuration providers configurations connection connectionString constructors control controls contructor CSV CTS .net types conversion database DataGridView DataSource DataTable DataType DBML delegates design pattern dispose double encoding Entity framework Events exception handling expiry fault contracts fault exceptions function pointers functions generics help HostingEnvironmentException IIS inner join instance management integrated mode javascript join left outer join LINQ LINQ join LINQ to SQL memory leak methods microsoft model driven app modes in IIS MSIL multiple catch blocks no primary key Nullable Osmos Osmotic Osmotic communication Osmotic communications page events page life cycle partial class PMI powerapps preserve precision points private contructor ProcessExit Project management properties property protect connectionString providerName providers query regular expression repository Responsive Web Design return type run-time RWD Saas self join session session expiry sessions singelton singleton pattern software as a service source control system SQLMetal string time management time-boxing toolstrip ToolStrip controls ToolStripControlHost tortoise SVN ToString() try catch finally update wcf web application web design web site web.config where-clause xml

Pages