Recipe 17.2. Localizing Request/Response EncodingProblemYou are developing an application for a specific region, and you want to tell the browser which character set to use in rendering the page. SolutionSet 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> DiscussionThe 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.
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).
The requestEncoding attribute is used to specify the assumed encoding for incoming requests. This includes posted data and data passed in the URL. Generally, the requestEncoding attribute is set to the same character set as the responseEncoding attribute. If your web.config file does not contain a <globalization> element with responseEncoding and requestEncoding attributes set to a particular character set, the values defined in the machine.config file are used instead. By default, requests and responses are encoded in utf-8 format. If your machine.config file does not contain a <globalization> element with the responseEncoding and requestEncoding attributes set to the given character set, the encoding defaults to the computer's region locale setting.
See AlsoThe "<globalization> Element" in the MSDN Library |