asp.net URL to pass Chinese garbled solution

Source: Internet
Author: User

ASP tutorial. Net URL Pass Chinese garbled solution

1. Set the 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 you are passing a Chinese parameter to an. aspx file from an. html file (that is, not using 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= "Web Effects" >
function Gourl ()
{
var name = "Chinese parameter";
Location.href = "B.aspx?name=" +escape (name);
}
</script>
<body onclick= "Gourl ()" >
>> to receive
String name = request.querystring["Name"];
Response.Write (Server.urldecode (name));


Instance method

In Project A
String url = "http://" + arr[2] + ": 111/loginif.aspx?uid=" + Server.URLEncode (arr[0]) + "&pwd=" + arr[1]; Chinese Account Transfer Code

Clientscript.registerclientscriptblock (This.gettype (), "This", "<script>window.open" (' + URL + ') </script > "); This pass parameter UID is in Chinese

B in Project receive
Userloginif (Server.URLEncode (request["UID"].tostring ()), request["pwd"].tostring ()); Chinese must turn code


Specify encoding
Sending party Server.URLEncode ("Chinese", Encoding.GetEncoding ("gb2312"));
Receiver Server.urldecode (request["key"], encoding.getencoding ("gb2312"));


Userloginif (Server.urldecode (request["UID"].tostring ()), request["pwd"].tostring ());


Encode is encoded, decode is decoding.

If not yet,
Use the Post method, or use Requestheader, or
Consider using WebService to do proxy forwarding.

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.