JavaScript Editor jscript editor     Web designer 



Main Page

Internally, the code behind ASP.NET Web pages handles all string data as Unicode. You can set how the page encodes its response, which sets the CharSet attribute on the Content-Type part of the HTTP header. This enables browsers to determine the encoding without a meta tag or having to deduce the correct encoding from the content. You can also set how the page interprets information that is sent in a request.

Finally, you can set how ASP.NET interprets the content of the page itself — in other words, the encoding of the physical .aspx file on disk. If you set the file encoding, all ASP pages must use that encoding. Notepad.exe can save files that are encoded in the current system ANSI codepage, in UTF-8, or in UTF-16 (also called Unicode). The ASP.NET runtime can distinguish between these three encodings. The encoding of the physical ASP.NET file must match the encoding that is specified in the file in the @ Page encoding attributes.

NoteNote

Some designers, such as Visual Studio 2005, can save .aspx files that use different encodings.

Caution noteCaution

The name of the Web application might not display correctly on a user's computer, if the name uses a double-byte character set (DBCS) that is not the language of the user's operating system. On earlier versions of Microsoft FrontPage server extensions and on Microsoft Internet Information Services (IIS) versions 5.1 and earlier, the project name must also match the language of the operating system for the Web server in order to display correctly.

To specify encoding

  • To set the encoding for all pages, add a Globalization property to the Web.config file, and then set its fileEncoding, requestEncoding, and responseEncoding attributes, as shown in the following example:

    В CopyCode imageCopy Code
    <configuration>
      <system.web>
        <globalization
          fileEncoding="utf-8"
          requestEncoding="utf-8"
          responseEncoding="utf-8"
          culture="en-US"
          uiCulture="de-DE"
        />
      </system.web>
    </configuration>
  • To set the encoding for an individual page, set the RequestEncoding and ResponseEncoding attributes of the @ Page directive, as shown in the following example:

    В CopyCode imageCopy Code
    <%@ Page RequestEncoding="utf-8" ResponseEncoding="utf-8" %>
    NoteNote

    You cannot set the fileEncoding attribute, because it applies to the file itself.

See Also



JavaScript Editor jscript editor     Web designer