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