Localization Support
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("de-DE"))%>
The result is as follows:
Tuesday, March 16, 2010 4:49 PM
Dienstag, 16. März 2010 16:49
Configuration Settings
When creating ASP.NET pages or code-behind modules, developers can use the
.NET Framework class library to provide features necessary for a globalized 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 determine the way in which request data and
response data are encoded, respectively.
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:
<%@Page Culture="fr-FR" UICulture="fr-FR" ResponseEncoding="utf-8"%>
Note: Within a page, the culture values can be changed programmatically by setting
Thread.CurrentCulture and Thread.UICulture.
- ASP.NET supports a wide range of encodings for .aspx files, request data, and response data.
- Support for locale-dependent data is provided by the CultureInfo class, where the two
values CurrentCulture and CurrentUICulture are tracked.
- Internationalization settings can be configured for each computer, for each directory, and for each page.
Copyright 2001-2002 Microsoft Corporation. All rights reserved.