2025-04-27 07:49:33 -04:00

112 lines
6.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<TITLE>Setting the Code Page for String Conversions</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
TempString = navigator.appVersion
if (navigator.appName == "Microsoft Internet Explorer"){
// Check to see if browser is Microsoft
if (TempString.indexOf ("4.") >= 0){
// Check to see if it is IE 4
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else {
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
}
}
else if (navigator.appName == "Netscape") {
// Check to see if browser is Netscape
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
}
else
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_OnLoad()
Dim frmContents
On Error Resume Next
If Not Parent Is Nothing Then
Set frmContents = Parent.Contents
If Not frmContents Is Nothing Then
frmContents.Window.TOCSynch_Click
End If
End If
End Sub
//--></SCRIPT><META NAME="DESCRIPTION" CONTENT="Internet Information Services reference information">
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="MS-IT-LOC" Content="Internet Information Services">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H2><A NAME="_k2_setting_the_code_page_for_string_conversions"></A><SUP></SUP>Setting the Code-Page for String Conversions</H2>
<P>A <I>codepage</I> is an internal table that the operating system uses to map symbols (letters, numerals, and punctuation characters) to a number. Different codepages provide support for the character sets used in different languages. Code pages are referred to by number; for example, codepage 932 represents the Japanese character set, and codepage 950 represents one of the Chinese character sets.</P>
<P>Active Server Pages, and the script engines it supports, internally use Unicode, a 16-bit fixed-width character encoding standard. If you author all of your pages in the default codepage of the Web server, ASP automatically converts strings. If your script was not created for the Web server's default codepage or the browser's default codepage, you need to specify the code-page so that strings are correctly converted as they are passed during the following scenarios:
<UL type=disc>
<LI>Between the script and the ASP engine.</li>
<LI>Between the ASP engine and the browser.</li>
<LI>Between the ASP engine and COM components.</li>
</UL>
<P>To specify the codepage for an ASP page, use the AspCodePage metabase property, the @CODEPAGE directive, the Session.CodePage property, or the Response.CodePage property. For example, to set the codepage to Japanese, set the AspCodePage property for your application to 932 using one of the following commands:</P>
<PRE><CODE>&lt;%@ CODEPAGE = 932 %&gt;
&lt;% Session.CodePage = 932 %&gt;
&lt;% Response.CodePage = 932 %&gt;
</CODE></PRE>
<P>Keep in mind that the ASP page must be saved in the file format that matches the @CodePage directive. For example, if @CodePage is set to 65001, the Web page must be saved in UTF-8 format.&nbsp; If @CodePage is set to 932, the Web page must be saved in ANSI format on a computer that has the default system locale set to Japanese.</P>
<P>As ASP processes the content and script on this page, it uses the code page you have specified to convert characters from your script's character set into Unicode. For example, the value that refers to the letter "a" in ANSI is converted into the different value that refers to the letter "a" in Unicode.</P>
<PRE></PRE>
<P>When a script is executed, Response.CodePage determines how characters are encoded. If Response.CodePage is not set explicitly in a Web page, then it is set implicitly with this hierarchy:
<UL type=disc>
<LI>If Sessions are enabled, and Session.CodePage is set explicitly, Session.CodePage sets Response.CodePage. Else,</li>
<LI>If @CodePage is defined at the top of the page, @CodePage sets Response.CodePage. Else,</li>
<LI>If the AspCodePage metabase property for the application is set to something other than 0, AspCodePage sets Response.CodePage. Else,</li>
<LI>The Web server's default system codepage sets Response.CodePage.</li>
</UL>
<P>There can only be one codepage per Web page. If you use @CodePage and one other method, make sure you set them to the same codepage, or one of them to UTF-8. @CodePage affects literal strings and the other methods affect string variables, so if two incompatible codepages are mixed, the browser displays the literal strings incorrectly.</P>
<P>When ASP sends a Web page to a browser, the browser needs to know what character set to use to display the page properly, and the language pack for that character set must be installed on the computer. To specify the character set, use one of the following commands:</P>
<PRE><CODE>&lt;META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=windows-1251"&gt;
&lt;% Response.Charset = "windows-1252"</CODE></PRE>
<P>If you are temporarily changing the code page for a portion of your script, be sure to set the codepage back to its original value. The following script shows one way to temporarily change the codepage:</P>
<PRE><CODE>&lt;%@ CodePage = 65001 %&gt;
&lt;!-- Welcome to my home page in UTF-8 --&gt;
&lt;%
Response.Write "The Session codepage is " &amp; Session.CodePage &amp; "&lt;BR&gt;"
Response.CodePage = 932
Response.Write "The codepage for this page has been changed with Response.CodePage&lt;BR&gt;"
Response.Write "The Response codepage is " &amp; Response.CodePage &amp; "&lt;BR&gt;"
Response.Write "The Session codepage is still " &amp; Session.CodePage &amp; "&lt;BR&gt;"
%&gt;</CODE></PRE>
<P>For more examples and information, please see the documentation for <A HREF="apro8u91.htm">AspCodePage</A>, <A HREF="dire7ixx.htm">@CodePage</A>, <A HREF="vbob4ht1.htm">Session.CodePage</A>, <A HREF="vbob150l.htm">Response.CodePage</A>, and <A HREF="vbob7fw4.htm">Response.Charset</A>.</P>
<hr class="iis" size="1">
<p align="center"><em><a href="../../../common/colegal.htm">&copy; 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
</BODY>
</HTML>