Introduction to CodePage, Response.CodePage and Session.CodePage differences in ASP

Source: Internet
Author: User
Tags sessions metabase

For the differences between codepage, Response.CodePage and Session.CodePage, the MSDN notes are as follows:


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 Respon SES in a session.

The effect is that codepage affects static text, Response.CodePage affects dynamic text, the Session.CodePage function is the same as response.codepage, but it is more scoped and affects all responses of the same session.

1, codepage and Response.CodePage test


<%@ codepage=65001%>
<%
response.charset= "Utf-8"

Response.CodePage = 936
Response.Write ("This is dynamic text.) ")
%>
This is static text.

<%@ codepage=65001%>
<%
response.charset= "gb2312"

Response.CodePage = 936
Response.Write ("This is dynamic text.) ")
%>


This is static text.

<%@ codepage=936%>
<%
response.charset= "gb2312"

Response.CodePage = 936
Response.Write ("This is dynamic text.) ")
%>
This is static text.

Description: The Web page file is encoded as UTF-8.

2, Response.CodePage and Session.CodePage test


<%
response.charset= "gb2312"

Session.CodePage = 65001
Response.CodePage = 936
Response.Write ("This is dynamic text.) ")
%>
This is static text.


<%
response.charset= "gb2312"

Response.CodePage = 936
Session.CodePage = 65001
Response.Write ("This is dynamic text.) ")
%>
This is static text.

3, CodePage, Response.CodePage and session.codepage order of values

If codepage is not set:


If @CODEPAGE is isn't explicitly set in a page, it's implicitly set by the AspCodePage metabase or by the system a NSI code page.

If Response.CodePage is not set:


If Response.CodePage is isn't explicitly set in a page, it's implicitly set by Session.CodePage, if sessions are enabled. If sessions are not enabled, Response.CodePage are set by @CodePage, if @CodePage was present in the page. If there is no @CodePage in the page, Response.CodePage are set by the AspCodePage metabase property. If the AspCodePage metabase is not set, or set to 0, Response.CodePage is set by the system ANSI CodePage.

If Session.CodePage is not set:


If Session.CodePage is isn't explicitly set on a page and the It is implicitly set by the AspCodePage metabase property. If The AspCodePage property isn't set, or set to 0, the Session.CodePage are set by the System ANSI code page. Session.CodePage is no longer implicitly the set by @CodePage, as it was for IIS 5.0 and earlier versions. This is made because one @CodePage could change the "code page for" entire session. Now, the @CodePage and Response.CodePage affect only single responses while Session.CodePage affects all responses in a Sessi On.

4, the role of Response.Charset

Or look at the MSDN instructions:


If The code page is set in a page, then Response.Charset should also to be set. The code page value specifies to IIS you to encode the data when building the response, and the CharSet value tells the BR Owser 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.