|
One of the principal advantages of hosting an application in a Web browser is that the potential audience for that application can be worldwide. Globalization is the process of designing an application so that it can adapt to different cultures. . Globalization is the process of designing and developing an application so that it supports user interfaces and regional data for users in target cultures.
ASP.NET internally uses Unicode. In addition, ASP.NET utilizes the String class of the .NET Framework class library and the related utility functions, which are also internally Unicode. When interfacing with the outside world, ASP.NET can be configured in several ways to use a defined encoding, which includes the encoding of .aspx files, request data, and response data. For example, it is possible to store .aspx files with Unicode encoding and convert the HTML output of a page to an ANSI code page like ISO-8859-1.
Properties of a locale are accessible through the CultureInfo class. Additionally, ASP.NET tracks two properties of a default culture per thread and request: CurrentCulture for the default of locale-dependent functions and CurrentUICulture for locale-specific lookup of resource data. The following code displays the culture values on the Web server. Note that the CultureInfo class is fully qualified.
<%@Import Namespace="System.Globalization"%> <%=CultureInfo.CurrentCulture.NativeName%> <%=CultureInfo.CurrentUICulture.NativeName%>
The result is as follows: English (United States) English (United States)
For locale-dependent data like date/time formats or currency, ASP.NET leverages the support of the .NET Framework class library in the common language runtime. Code on ASP.NET pages can use locale-dependent formatting routines like DateTime.Format. For example, the following code displays the current date in a long format: the first line according to the system locale, the second one according to the German ("de") locale:
<%=DateTime.Now.ToString("f")%> <%=DateTime.Now.ToString("f", new System.Globalization.CultureInfo("deDE"))%> The result is as follows:
Thursday, February 28, 2008 6:16 AM Donnerstag, 28. Februar 2008 06:16
When creating ASP.NET pages or code-behind modules, developers can use the .NET Framework class library to provide features necessary for a globalize environment or to localize the application. ASP.NET also provides configuration settings to ease development and administration of ASP.NET applications.
ASP.NET utilizes configuration files to provide directory settings that are usually also inherited by subdirectories. Each file can contain a Globalization section in which you can specify default encodings and cultures. Values are valid if they are accepted by the related classes Encoding and CultureInfo. You can find more information about the Encoding and CultureInfo classes in the .NET Framework SDK.
Within the Globalization section, the value of fileEncoding determines the way in which ASP.NET encodes .aspx files; the values of requestEncoding and responseEncoding The attributes of the Globalization section in the Web.config file can also be specified on the Page directive (with the exception of fileEncoding, because it applies to the file itself). These settings are only valid for a specific page and override the settings of the Web.config file. The following sample directive specifies that the page should use French culture settings and UTF-8 encoding for the response:
determine the way in which request data and response data are encoded, respectively. <%@Page Culture="fr-FR" UICulture="fr-FR" ResponseEncoding="utf-8"%>
Within a page, the culture values can be changed programmatically by setting Thread.CurrentCulture and Thread.UICulture. |