Analysis of garbled characters during ASP. NET running but web Testing

Source: Internet
Author: User

When the Asp.net website runs normally, perform a web test as follows:

A strange thing occurred during the web test, as shown in,

 

In this case, we first analyze the problem. The possibility of Garbled text is the webpage encoding problem. Unicode encoding is gradually becoming the most common solution supported by multiple languages. Unicode-Encoded chinese web pages are compatible with various platforms and browsers. UTF-8 is a storage/exchange implementation method of Unicode. Unicode codes of different numeric ranges are encoded in a variable length mode. All ASCII characters occupy 1 byte, and those greater than 0x7f occupy 2 to 4 bytes. We can see that all ASCII files are directly compatible with UTF-8. In addition, for files with a large portion of the ASCII characters such as the Web source code, it is typically more space-saving than other Unicode storage/Interchange Formats (such as UTF-16, utf-32, and so on. Therefore, UTF-8 is widely used in website design.

All pages on my website are encoded in gb2312 format, but ASP. the default encoding in net is UTF-8, so we can find this problem from the wrong page, although we changed the request property from the original UTF-8 to gb2312 in the test case, but the test still found that the response returned packet was returned in the form of a UTF-8, in this way, the entire webpage can be garbled.

 

Solution:

The first solution: the use of ASP. NET encoding default way of UTF-8, the whole site of all Web Page code modified to the form of UTF-8, do not use gb2312.

Solution 2: If you still want to use gb2312 encoding for the webpage page, you can add the following code to the website configuration file web. config.

<Configuration>
<System. Web>
<Globalization fileEncoding = "gb2312" requestEncoding = "gb2312" responseEncoding = "gb2312" responseHeaderEncoding = "gb2312"/>
</System. web>
<Configuration>
WEB Testing after modification

 

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.