Asp.net garbled Solution

Source: Internet
Author: User

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.
.

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.