Session.CodePage

针对会话中的所有的响应,Session.CodePage属性指示了在内在的对象中,如何编码字符串。code page是一个字符集,可能包含数字、标点符号、以及其它字形。对于不同的语言,code page是各不相同的。有些语言,比如说日语和印第语,具有多字节字符,与此同时另一些语言,比如说英语和德语,只需要一字节来代表每个字符。CodePage属性是可读、可写的。

句法

Session.CodePage(=CodepageID)

参数

CodepageID
一个整型数,代表字符格式化code page。你可以在MSDN Web Workshop上找到code page整型数,在FamilyCodePage列的下面。

适用于

Session对象

备注

显式地设置Session.CodePage会影响会话中的所有的响应。Session.CodePage会隐式地在每个网页上设置Response.CodePage。一定得启用会话才能使用Session.CodePage

如果没有显式地在网页上设置Session.CodePageAspCodePage元数据属性会潜在地设置它。如果没有设置AspCodePage,或者它被设置为0,就由系统ANSI code page设置Session.CodePageSession.CodePage不再由@CodePage隐式设置了,因为它是针对IIS 5.0及更早的版本的。已经做了这个改变,因为一个@CodePage可以改变整个会话的code page。现在,@CodePageResponse.CodePage只影响单个响应,与此同时Session.CodePage影响一个会话中的所有响应。

对于每个响应主体,只可以有一种code page,否则就会显示错误的字符。如果你在两个网页中显式地设置了code,其中一个被另一个调用,通过#includeServer.ExecuteServer.Transfer调用,通常父网页决定了code page。唯一的例外是,在一个Server.Execute调用中,如果在父网页中显式地设置了Response.CodePage。在这种情况下,子网页中的@CodePage命令会覆盖父网页的code page。

Literal strings in a script are still encoded by using @CodePage (if present) or the AspCodePage metabase value (if set), or the system ANSI code page. If you set Response.CodePage or Session.CodePage explicitly, do so before sending nonliteral strings to the client. If you use literal and nonliteral strings in the same page, make sure the code page of @CodePage matches the code page of Session.CodePage, or the literal strings are encoded differently from the nonliteral strings and displayed 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, Response.Charset also should be set. The code page value specifies to IIS how to encode the data when building the response; and the charset value specifies to the browser how to decode the data when displaying the response. The CharsetName ofResponse.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. They will only be 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 the Regional and Language Options in the Control Panel.

必备条件

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

如果你喜欢这篇文章,敬请给站长打赏↑

除特别注明外,本站所有文章均为本站站长原译,转载请注明出处。