Getting Started
  Introduction
  What is ASP.NET?
  Language Support

ASP.NET Web Forms
  Introducing Web Forms
  Working with Server Controls
  Applying Styles to Controls
  Server Control Form Validation
  Web Forms User Controls
  Data Binding Server Controls
  Server-Side Data Access
  Data Access and Customization
  Working with Business Objects
  Authoring Custom Controls
  Web Forms Controls Reference
  Web Forms Syntax Reference

ASP.NET Web Services
  Introducing Web Services
  Writing a Simple Web Service
  Web Service Type Marshalling
  Using Data in Web Services
  Using Objects and Intrinsics
  The WebService Behavior
  HTML Pattern Matching

ASP.NET Web Applications
  Application Overview
  Using the Global.asax File
  Managing Application State
  HttpHandlers and Factories

Cache Services
  Caching Overview
  Page Output Caching
  Page Fragment Caching
  Page Data Caching

Configuration
  Configuration Overview
  Configuration File Format
  Retrieving Configuration

Deployment
  Deploying Applications
  Using the Process Model
  Handling Errors

Security
  Security Overview
  Authentication & Authorization
  Windows-based Authentication
  Forms-based Authentication
  Authorizing Users and Roles
  User Account Impersonation
  Security and WebServices

Localization
  Internationalization Overview
  Setting Culture and Encoding
  Localizing ASP.NET Applications
  Working with Resource Files

Tracing
  Tracing Overview
  Trace Logging to Page Output
  Application-level Trace Logging

Debugging
  The SDK Debugger

Performance
  Performance Overview
  Performance Tuning Tips
  Measuring Performance

ASP to ASP.NET Migration
  Migration Overview
  Syntax and Semantics
  Language Compatibility
  COM Interoperability
  Transactions

Sample Applications
  A Personalized Portal
  An E-Commerce Storefront
  A Class Browser Application
  IBuySpy.com

  Get URL for this page

Setting Culture and Encoding


Encodings

Internally, ASP.NET handles all string data as Unicode. By using the ResponseEncoding attribute in the following sample, ASP.NET is asked to also send the page with UTF-8 encoding. Note that any arbitrary encoding could be chosen without affecting the .aspx file. ASP.NET also sets the CharSet attribute on the Content Type of the HTTP header according to the value of ResponseEncoding. This enables browsers to determine the encoding without a metatag or having to guess the correct encoding from the content.

 
VB i18n_encodings.aspx

[Run Sample] | [View Source]

Note: If some characters appear as empty rectangles, you must install the additional language support for Japanese and Hebrew. To do this on a Windows 2000 platform, open Regional Options on the Control Panel and add the required language support.

The preceding sample demonstrates how to use different national character sets on the same page. The page contains English text (ASCII), German text with one umlaut character, Japanese text, and Hebrew text (uses dir="rtl"). The source for the page itself is stored with codepage-neutral UTF-8 encoding, as specified in Web.config.

<configuration> <system.web> <globalization fileEncoding="utf-8" ... /> </system.web> </configuration>

The Page directive specifies ResponseEncoding on the page itself:

<%@Page ... ResponseEncoding="utf-8"%>

Note: The ResponseEncoding in Web.config is also specified as UTF-8, so repeating it on the page is redundant. However, if the .aspx file is moved to a server that does not use UTF-8, the file would still specify the right encoding.

Using CultureInfo

Code on ASP.NET pages can use the CultureInfo class to supply localized settings. In the following sample, the properties of a culture, initially the culture of the server, is set as follows:

VB

If the name of a new culture is submitted, it will be used instead:


culture = New CultureInfo(NewCulture.Value)
VB

The submitted culture is set to be the new default value and some properties are displayed:


<%
Thread.CurrentThread.CurrentCulture = culture
%>
...
Current Culture is <%= CultureInfo.CurrentCulture.Name %>
(<%=Thread.CurrentThread.CurrentCulture.Name%>),
<%= CultureInfo.CurrentCulture.EnglishName %>/<%=CultureInfo.CurrentCulture.NativeName%>,
The localized date is: <%= DateTime.Now.ToString("D", CultureInfo.CurrentCulture) %>
VB

 
VB i18n_cultureinfo.aspx

[Run Sample] | [View Source]


Using RegionInfo

Code on ASP.NET pages can also use the RegionInfo class to supply regional settings. In the following sample, the properties of a region are displayed. The initial display is the server's default region.

VB

On subsequent requests the entered region is displayed:


region = New RegionInfo(NewRegion.Value)
VB

 
VB I18N_Regional.aspx

[Run Sample] | [View Source]

Section Summary

  1. ASP.NET can use pages that are stored with UTF-8 encoding to support different national characters.
  2. The CultureInfo class can be set and used programmatically to localize pages.
  3. The RegionInfo class can be used to provide regional settings on ASP.NET pages.


Copyright 2001 Microsoft Corporation. All rights reserved.

GoToMyPC | ASP.NET Knowledge Base