Decode UrlDecode and encode UrlEncode

Source: Internet
Author: User
Tags urlencode

In front of the foreground to pass parameters, in the foreground code, in the background to receive parameters, with decode to decode;

If the URL contains special characters such as:&, HTML tags <tr><td> etc. cause the URL cannot be parsed correctly need to encode and decode ur to prevent errors in the transmission process

Server.urldecode (); Server.URLEncode (); it's two paired methods.
function is in the URL to pass the argument if the direct Chinese can be a problem (for the Chinese parameter Support Section perfect), so first use Server.URLEncode ("Chinese parameter"); encoding
To another page to accept the time in the use of Server.urldecode ("code after the parameter is generally the form of%+ 16 binary)"; decoding to get Chinese parameters
Server.URLEncode and Server.urldecode (a solution for URL delivery in Chinese ) may cause problems when the address passes the parameter, which is useful. Program Design ASP . 2010-10-10 20:57:46 Read Bayi comment 0 font size: big Middle Small subscription

1. Set up the Web. config file.
<system.web>
......
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
......
</system.web>
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);
}
</script>
<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.

Dataurl = Server.urldecode (Dataurl);

Dataurl: "/mvcconfig/ui/list/getlist?" Tmplcode=commonapplyselect "

The difference is that the Server

This is a function of JavaScript.
encodeURI ("URL address")//code
decodeURI ("URL address")//decoding
This is the method of ASP.
Server.URLEncode ("URL address")//code
Server.urldecode ("URL address")//decoding

Decode UrlDecode and encode UrlEncode

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.