Asp.net garbled Solution
The configuration in Web. comfig is the same:
<Globalization requestEncoding = "gb2312" responseEncoding = "gb2312"/>
The Header part of the page also has
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
Strange,
I had to use the stupid method:
Write parameters:
Copy the Code as follows:
String strurl = PreUrl + "? Word = {0} & sort = {1} & check = {2 }";
Strurl = string. format (strurl, HttpUtility.UrlEncode(this.txt SearchTxt. text. trim (), System. text. encoding. getEncoding ("GB2312"), this. radioSortDesc. selectedIndex. toString (), CheckState. toString ());
Page. Response. Redirect (strurl );
// Note that the encoding method is gb2312.
Read parameters:
Copy the Code as follows:
Try
{If (Page. Request. QueryString ["word"]! = Null)
{_ Word = Convert. ToString (HttpUtility. UrlDecode (Page. Request. QueryString ["word"], System. Text. Encoding. GetEncoding ("GB2312 ")));}
}
Catch {_ word = String. Empty ;}
/// Note that the encoding method is gb2312, which corresponds to the preceding
Later, I read Mencius's article and found a better solution:
Use Javascript!
Write a method to the base class page
Copy the Code as follows:
Public void PageLocation (string chineseURL)
{
If (chineseURL = null | chineseURL. Trim (). Length = 0)
{Return; // It may not be a legal URL, Tony 2007/11/15
}
Page. clientScript. registerStartupScript (this. getType (), "AgronetPageLocationTo", "<script type = 'text/javascript 'language = 'javascript'> window. location. href = '"+ chineseURL +"'; </script> ");
}
Then, call
Copy the Code as follows:
String strurl = PreUrl + "? Word = {0} & sort = {1} & check = {2 }";
Strurl = string. Format (strurl, this.txt SearchTxt. Text. Trim (), this. radioSortDesc. SelectedIndex. ToString (), CheckState. ToString ());
PageLocation (strurl );
Note that the latter method uses javasrcept. in actual application, Chinese parameters need to be kept during paging. It is best to use the window. Location. Href method!
Finally, if you want to talk to the. net background code in javascript, you can do this:
Copy the Code as follows:
<Script language = "JavaScript">
Function GoUrl ()
{
Var Name = "Chinese parameter ";
Location. href = "B. aspx? Name = "+ escape (Name );
}
</Script>
<Body onclick = "GoUrl ()">
Receive:
Copy the Code as follows:
String Name = Request. QueryString ["Name"];
Response. Write (HttpUtility. UrlDecode (Name ));
Key points:
Encode the passed Chinese parameters and decode them upon receiving them.
.