Chinese garbled is the Web site development will often encounter problems, today we talk about the URL address in Chinese character parameters to pass garbled solution, there is a need for friends can refer to.
In the CS file in the time to pass the UrlEncode:
Response.Redirect ("b.asp tutorial x?") Name= "+server.urlencode (Name));
Use UrlDecode when taking the ginseng:
Response.Write (Server.urldecode (request.querystring["Name"));
In the script, you use escape when you pass the argument:
location.href = "b.aspx?" Name= "+escape (Name);
The UrlDecode is still used when the argument is received:
Response.Write (Server.urldecode (request.querystring["Name"));
Summary of the three point method
There are generally 3 ways to solve these problems:
1. Set up Web.config file
<system.web>
......
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
......
</system.web>
2. Before passing the Chinese language, the Chinese parameters to be passed are encoded and decoded at the time of receiving.
>> to deliver
string Name = "Chinese parameters";
Response.Redirect ("B.aspx?") Name= "+server.urlencode (Name));
>> to receive
string Name = request.querystring["name"];
Response.Write (Server.urldecode (Name));
3. If it's from. HTML file to. Aspx file to pass the Chinese parameter (that is, do not use the Redirect () method for URL conversion from the background). To encode the passed Chinese parameters and decode them when they are received.
>> to deliver
<script language= "JavaScript" >
function Gourl ()
{
var Name = "Chinese parameter";
Location.href = "B.aspx?" Name= "+escape (Name);
}
<body onclick= "Gourl ()" >
>> to receive
String Name = request.querystring["name"];
Response.Write (Server.urldecode (Name))