Solution to garbled problem of Utf-8 and Gb2312 encoding conversion in ASP

Source: Internet
Author: User

The problem is that when you browse UTF-8 encoding, the server outputs html by default with the UTF-8 engine, and when you browse the page of GB2312, it still uses the UTF-8 to output the page which should be GB2312 encoding, so it will be garbled.

I had to worry about this problem for one morning and finally got the blue ideal solution.

First, let's take a look at the four attributes provided by the Session object.
1. CodePage read/write. Integer.
Defines the Code Page used to display Page content in a browser ). The code page is the numeric value of the character set. 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 daily text. (This attribute is used here)
2. LCID read/write. Integer.
Defines the page Region ID (LCID) sent to the browser ). LCID is an abbreviation of an international standard that uniquely identifies a region. For example, 2057 defines that the currency symbol of the current region is 'shanghai '. LCID can also be used in statements such as FormatCurrency, as long as there is an optional LCID parameter. LCID can also process commands in ASP <%... %>, And takes precedence over the settings in the LCID attribute of the session. This chapter provides a list of ASP processing commands.
3. SessionID is read-only. Long integer.
Returns the session identifier of the session. This identifier is generated by the server when the session is created. It is unique only during the lifetime of the parent Application object, so it can be reused when a new Application starts.
4. Timeout read/write. Integer.
Defines the timeout period in minutes for this session. If the user does not refresh or request a webpage during the timeout period, the session ends. You can modify the settings on each webpage as needed. The default value is 10 min. This time should be shorter on sites with high usage!

Below are several commonly used 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%> Korean
<% @ Codepage = 866%> Russian

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

1. Add the Gb2312 encoding page
<% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "936" %>
<% Session. CodePage = 936%>
Add multiple
<% Response. charset = "BG2312" %>

2. Add <% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %> to the UTF-8 encoding page.
<% Session. CodePage = 65001%>
<% Response. charset = "UTF-8" %>

This is the simplest and most effective method.

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.