asp中CodePage、Response.CodePage和Session.CodePage區別介紹

來源:互聯網
上載者:User

關於CodePage、Response.CodePage和Session.CodePage三者的區別,MSDN說明如下:


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.

大意是CodePage影響靜態文本,Response.CodePage影響動態文本,Session.CodePage的作用和Response.CodePage相同,只是它的作用範圍更大,影響同一會話的所有響應。

1、CodePage和Response.CodePage的測試


<%@ CodePage=65001 %>
<%
    Response.Charset="utf-8"   
   
    Response.CodePage = 936
    Response.Write("這是動態文本。")   
%>
這是靜態文本。

<%@ CodePage=65001 %>
<%
    Response.Charset="gb2312"   
   
    Response.CodePage = 936
    Response.Write("這是動態文本。")   
%>


這是靜態文本。

<%@ CodePage=936 %>
<%
    Response.Charset="gb2312"   
   
    Response.CodePage = 936
    Response.Write("這是動態文本。")   
%>
這是靜態文本。

說明:網頁檔案編碼為UTF-8。

2、Response.CodePage和Session.CodePage的測試


<%
    Response.Charset="gb2312"  
   
    Session.CodePage = 65001
    Response.CodePage = 936
    Response.Write("這是動態文本。")   
%>
這是靜態文本。


<%
    Response.Charset="gb2312"  
   
    Response.CodePage = 936
    Session.CodePage = 65001
    Response.Write("這是動態文本。")   
%>
這是靜態文本。

3、CodePage、Response.CodePage和Session.CodePage取值順序

若未設定CodePage:


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.

若未設定Response.CodePage:


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 codepage.

若未設定Session.CodePage:


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

4、Response.Charset的作用

還是看MSDN的說明:


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.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.