Two solutions for garbled URL passing parameters in Asp.net

Source: Internet
Author: User

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

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 Article To find a better solution:
Use JavaScript!
Write a method to the base class page
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
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. net background Code for dialog, you can do this:


receive:
string name = request. querystring ["name"];
response. write (httputility. urldecode (name);
the key point is:
encode the passed Chinese parameters and decode them when receiving them.
when you are young, you need to do things less nonsense and more.

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.