@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
The @CODEPAGE processing directive specifies how literal (static) strings are encoded in a Web page. A code page is a character set, which can include numbers, punctuation marks, and other glyphs. Codepages are not the same for each language. Some languages, such as Japanese and Hindi, have multibyte characters, while others, such as English and German, only need one byte to represent each character. The @CODEPAGE processing directive is write-only.
A code page can be represented in a table as a mapping of characters to single-byte values or multibyte values. Many code pages share the ASCII character set for characters in the range 0x00-0x7F.
@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
Syntax
<%@ CODEPAGE = codepage%>
@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
Parameters
codepage
An unsigned integer that represents a valid code page for the system that is running the ASP scripting engine.
@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
Remarks
Setting @CODEPAGE explicitly affects literal strings in a single response. Response.CodePage affects dynamic strings in a single response, and Session.CodePage affects dynamic strings in all responses in a session.
If @CODEPAGE is not explicitly set in a page, it is implicitly set by the AspCodePage metabase property or by the system ANSI code page.
There can be only one code page per response body, otherwise incorrect characters are displayed. If you set the code page explicitly in two pages, where one is called by the other by using #include, Server.Execute, or Server.Transfer, usually the parent page decides the code page. The only exception is if Response.CodePage is explicitly set in the parent page of a Server.Execute call. In this case, an @CodePage command in the child page overrides the parent code page.
If you set Response.CodePage or Session.CodePage explicitly, do so before sending non-literal strings to the client. If you use literal and non-literal strings in the same page, make sure the code page of @CODEPAGE matches the code page of Response.CodePage, or the literal strings are encoded differently from the non-literal strings and display incorrectly.
If the code page of your Web page matches the system defaults of the Web client, you do not need to set a code page in your Web page. However, setting the value is recommended.
If the code page is set in a page, then Response.Charset should also be set. The code page value specifies to IIS how to encode the data when building the response, and the charset value tells the browser how to decode the data when displaying the response. The CharsetName of Response.Charset must match the code page value, or mixed characters are displayed in the browser. Lists of CharsetNames and matching code page values can be found on MSDN Web Workshop under the columns for Preferred Charset Label and FamilyCodePage.
The file format of a Web page must be the same as the @CODEPAGE used in the page. Notepad enables you to save files in UTF-8 format or in the system ANSI format. For example, if @CODEPAGE is set to 65001 for UTF-8, the Web file must be saved in UTF-8 format. If @CODEPAGE is set to 1252, the Web file must be saved in ANSI format on an English or German system. If you want to save a page in the ANSI format for a language other than your system language, you can change your default System Locale settings in Regional and Language Options on the Control Panel. For example, after you change your system locale to Japanese, any files you save in ANSI format are saved using the Japanese code page and are only readable from a Japanese system locale.
If you are writing and testing Web pages that use different code pages and character sets (for example, if you are creating a multilingual Web site), remember that your test client computer must have the language packs installed for each language you want to display. You can install language packs from Regional and Language Options on the Control Panel.
@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
Example Code
For more information, see the example for Response.CodePage.
@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
Requirements
Client: Requires Windows XP Professional, Windows 2000 Professional, or Windows NT Workstation 4.0.
Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
Product: IIS
@CODEPAGE SyntaxParametersRemarksExample CodeRequirementsSee Also
Setting @CODEPAGE explicitly affects literal strings in a single response. Response.CodePage affects dynamic strings in a single response, and Session.CodePage affects dynamic strings in all responses in a session.
这句话很关键的是说明了Response.CodePage的作用范围是a single response,而SXNA中声明的Session.CodePage的作用范围是all responses in a session。
再看另外一句话。
If Response.CodePage is not explicitly set in a page, it is implicitly set by Session.CodePage, if sessions are enabled. If sessions are not enabled, Response.CodePage is set by @CodePage, if @CodePage is present in the page. If there is no @CodePage in the page, Response.CodePage is set by the AspCodePage metabase property. If the AspCodePage metabase property is not set, or set to 0, Response.CodePage is set by the system ANSI code page.
这句话我乍一看,把意思理解成了这样:在sessions are enabled的时候,如果Response.CodePage没有声明,则Response.CodePage会被Session.CodePage赋值。如果sessions are not enabled的时候, 如果@CodePage已声明,则Response.CodePage会被@CodePage赋值,等等.............
如果仅仅按照上面的解释的话,我实际上是很糊涂的,因为我们都是用的中文操系统,当每一次进入浏览器的时候你可以尝试输出Session.CodePage,能看到他都是936!为什么进入Z-blog的时候他不把默认的Session.CodePage的936赋给Response.CodePage呢?反而把@CodePage给了Response.CodePage?什么情况下Session.CodePage才赋值给Response.CodePage呢?原文的sessions are enabled应该如何理解呢?
If you set Response.CodePage or Session.CodePage explicitly, do so before sending non-literal strings to the client. If you use literal and non-literal strings in the same page, make sure the code page of @CODEPAGE matches the code page of Response.CodePage, or the literal strings are encoded differently from the non-literal strings and display incorrectly.