Asp.net url Chinese parameter passing garbled Solution

Source: Internet
Author: User

Js Code:

Var pname = encodeuri ('<% = productname %> '));

C # code:

 

Encoding: var name = server. urlencode (request. querystring ["pname"]); decoding: var productname = server. urldecode (param [2]);

Note: web. config is also configured on the Internet:

<Globalization requestencoding = "gb2312" responseencoding = "gb2312"/>,

Encoding
Sender server. urlencode ("Chinese", encoding. getencoding ("gb2312 "));
Receiver server. urldecode (request ["key"], encoding. getencoding ("gb2312 "));

I do not recommend this. This solves the garbled characters but may cause garbled characters in other places. The default encoding is UTF-8, which is more widely used than gb2312.


Summary and Examples

If the html file passes Chinese parameters to the. asp tutorial x 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 = "webpage effect">

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 ));

Summary:

In general. Set the web. config file. However, if you use javascript to call the webservice method (passing Chinese parameters to webservice ). The web. config file is invalid.

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.