How to transmit garbled characters in the parameters of Chinese characters in the asp.net url address? asp.net garbled characters

Source: Internet
Author: User

How to transmit garbled characters in the parameters of Chinese characters in the asp.net url address? asp.net garbled characters

Chinese Garbled text is a problem frequently encountered during website development. Today, let's talk about the solution to the Garbled text parameter passing in Chinese characters in url addresses. If you need it, refer to it.
Use UrlEncode when passing parameters in the cs file:

Response. Redirect ("B. asp tutorial x? Name = "+ Server. UrlEncode (Name ));

Use UrlDecode when receiving the parameter:

Response. Write (Server. UrlDecode (Request. QueryString ["Name"]);
Use escape when passing parameters in the script:

Location. href = "B. aspx? Name = "+ escape (Name );

UrlDecode is still used when parameters are received:

Response. Write (Server. UrlDecode (Request. QueryString ["Name"]);
Three methods are summarized.

There are generally three solutions:

1. Set the web. config file

<System. web>
......
<Globalization requestEncoding = "gb2312" responseEncoding = "gb2312" culture = "zh-CN" fileEncoding = "gb2312"/>
......
</System. web (www.111cn.net)>

2. Before passing Chinese characters, encode the Chinese parameters to be passed and decode them upon receiving them.
> Transfer

String Name = "Chinese parameter ";
Response. Redirect ("B. aspx? Name = "+ Server. UrlEncode (Name ));

> Receive

String Name = Request. QueryString ["Name"];
Response. Write (Server. UrlDecode (Name ));

3. If a Chinese parameter is transferred from the. HTML file to the. Aspx file (that is, Url conversion is not performed using the Redirect () method from the background ). Similarly, the passed Chinese parameters must be encoded and decoded upon receiving.
> Transfer

<Script language = "JavaScript">
Function GoUrl ()
{
Var Name = "Chinese parameter ";
Location. href = "B. aspx? Name = "+ escape (Name );
}
<Body onclick = "GoUrl ()">

> Receive

String Name = Request. QueryString ["Name"];
Response. Write (Server. UrlDecode (Name ))
From: http://www.111cn.net/net/160/38841.htm


How can I solve the garbled characters in the parameters passed by aspnet url?

<% = HttpContext. Current. Server. UrlEncode (Eval ("cnProName") %> ">

How can I call this method? Return Value in the method...
 
How to solve Chinese garbled characters when parameters are passed through URLs?

EncodeURI can be used for encoding before passing parameters into the Url

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.