Solving uft8 and gb2312 conversion garbled problems in ASP

Source: Internet
Author: User
Tags character set numeric value processing instruction

ASP program in the same site, if there are UTF-8 coding program, and GB2312 coding program, after browsing UTF-8 encoded pages, and then browse the current site GB2312 page, GB2312 encoded pages will appear garbled
-
The problem is that when you browse the UTF-8 encoding, the server defaults to use UTF-8 engine to output HTML, when you use the GB2312 page, it is still used UTF-8 to output the page should be GB2312 encoded, so will be garbled.

For the sake of bothering me one morning, finally the blue ideal was resolved.

First let's take a look at the Session object provides four properties.
1.CodePage read/write. Integral type.
Defines the code page that is used to display the content of a page in a browser. The code page is the numeric value of the character set, and different languages and places may use different code pages. For example, ANSI code page 1252 is used in American English and most European languages. Code page 932 is used for Japanese text. (This is the attribute we're going to use here.)
2.LCID read/write. Integral type.
Defines the page region identity (LCID) that is sent to the browser. The LCID is an international standard abbreviation that uniquely identifies a region, for example, 2057 defines the currency symbol for the current region as ' £ '. The LCID can also be used in statements such as FormatCurrency, as long as there is an optional LCID parameter. The LCID can also be set in the ASP processing instruction <%...%>, taking precedence over the settings in the LCID attribute of the session. A list of ASP processing instructions is provided later in this chapter
3.SessionID Read only. Long integral type.
Returns the session identifier for this session, which is generated by the server when the session is created. Only within the lifetime of the parent Application object, so a new application can be reused when it is started
4.Timeout read/write. Integral type.
Defines a time-out period in minutes for this session. If the user does not refresh or request a Web page during the timeout period, the session ends. Can be modified as needed on each Web page. The default value is 10min. The time should be shorter on a site with a high usage rate!

Here are a few common ANSI code pages
<%@ Codepage=65001%>utf-8
<%@ codepage=936%> Simplified Chinese
<%@ codepage=950%> Traditional Chinese
<%@ codepage=437%> American/Canadian English
<%@ codepage=932%> Japanese
<%@ codepage=949%> Han Wen
<%@ codepage=866%> Russian


Now let's talk about how to solve the problem and how to use it.
Add the following code to the common file conn.asp used in the Web site program:

1, Gb2312 code page to join
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%Session.CodePage=936%>
Finally add more
<%response.charset = "BG2312"%>


2, Utf-8 code page to add <% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<%Session.CodePage=65001%>
<%response.charset = "Utf-8"%>

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.