Server.URLEncode and Server.urldecode (solution for URL delivery in Chinese)

Source: Internet
Author: User

1. Set up the Web. config file.
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
2. Before passing the Chinese, the Chinese parameter to be passed is encoded, and then decoded when it is received.
>> for delivery
String Name = "Chinese parameter";
Response.Redirect ("B.aspx? Name= "+server.urlencode (Name));
>> to receive
String name = request.querystring["Name"];
Response.Write (Server.urldecode (Name));

3. If it is from. HTML file to. Aspx file to pass the Chinese parameter (that is, no Url translation from the background using the Redirect () method). It is necessary to encode the passed Chinese parameters and decode them when they are received.

JS in:

The escape () function encodes the string so that it can be read on all computers

You can use Unescape () to decode an escape () encoded string.
>> for delivery
<script language= "JavaScript" >
function Gourl ()
var Name = "Chinese parameter";
Location.href = "B.aspx?" Name= "+escape (Name);
<body onclick= "Gourl ()" >
>> to receive
String name = request.querystring["Name"];
Response.Write (Server.urldecode (Name));

Generally speaking. You can set the Web. config file. But if you call the WebService method with JavaScript (pass the Chinese parameter inside the WebService). Setting the Web. config file looks invalid.

Server.URLEncode and Server.urldecode (solution for URL delivery in Chinese)

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