17.1. Localizing Request/Response Encoding
Problem
You are developing an application for a specific region, and you want to tell the browser which character set to use in rendering the page.
Solution
Set the
requestEncoding
and responseEncoding
attributes of the <globalization>
element in web.config to the desired character set:
<system.web>
<globalization requestEncoding="iso-8859-1" responseEncoding="iso-8859-1" />
</system.web>
Discussion
The HTTP header returned to the browser in response to a request contains information not displayed but, nevertheless, controls how the browser displays the content it receives. Included in the header is information that specifies which character set has been used to encode the response data and, by implication, which character set the browser should use to display it.
Tip
The request and response encoding information for a page request can be viewed by setting the Trace
attribute of the @ Page
directive to true
and viewing the Request Details section.
ASP.NET lets you specify the character set used to encode the response data using the responseEncoding
attribute of the <globalization>
element in the web.config file, as shown earlier. The responseEncoding
attribute can be set to any valid character set. Table 17-1 lists some of the more common character sets used for European languages (English, French, German, and others).
Table 17-1. Common character sets
Character set name |
Description |
---|---|
iso-8859-1 |
Commonly called Latin 1; covers the Western European ... |
Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.