The method of asp.net Chinese character parameter passing in URL address

Source: Internet
Author: User
Tags urlencode

Chinese garbled is the Web site development will often encounter problems, today we talk about the URL address in Chinese character parameters to pass garbled solution, there is a need for friends can refer to.
In the CS file in the time to pass the UrlEncode:

Response.Redirect ("b.asp tutorial x?") Name= "+server.urlencode (Name));


Use UrlDecode when taking the ginseng:

Response.Write (Server.urldecode (request.querystring["Name"));

In the script, you use escape when you pass the argument:

location.href = "b.aspx?" Name= "+escape (Name);

The UrlDecode is still used when the argument is received:

Response.Write (Server.urldecode (request.querystring["Name"));

Summary of the three point method

There are generally 3 ways to solve these problems:

1. Set up 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 it's from. HTML file to. Aspx file to pass the Chinese parameter (that is, do not use 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= "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))

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.