Solution for transmitting Chinese Characters in URLs

Source: Internet
Author: User

1. Solve the problem through web. config

<System. Web>

<Globalization requestencoding = '"gb2312" response/encoding = 'gb2312 "Culture =" ZH-CN "fileencoding =" gb2312 "/>

</System. Web>

2. Set the ASPX page to know the Request Encoding of the same page as the ASPNET in the head.

<Head runat = "server">

<Title> </title>

<Meta http-equiv = "content_type" content = "text/html; charset = gb2312">

</Head>

3. encode the Chinese parameters to be passed and decode the parameters when receiving them.

Encoding method 1. httputility. urlencode

Is the frontend method:

<Asp: hyperlink id = "hyper" runat = "server"

Navigateurl = '<% # "B. aspx? Name "+ httpuility. urlencode (" Chinese ", system. Text. encoding. getencoding (" gb2312 ") %>'
Pass to B

</ASP: hyperlink>

Encoding method 2; server. urlencode

Is the background method:

String name = "Chinese ";
Response. Redirect ("B. aspx? Name = "+ server. urlencode (name ));

Encoding method 3: javascript encoding Transmission

Function gourl ()

{

VaR name = "Chinese ";

Location. href = "B. aspx? Name = "+ escape (name );

}

Accept the passed Value

If (request ["name"]! = NULL)

{

String name = request ["parm1"];

Response. Write (server. urlencode (name ));

}

In general, you can set web. config. If you use JavaScript to call WebService, the Web. config setting will be invalid.

4. Enable the machine to support Chinese Characters

1. If the preceding method is not correct, open the page in notepad and select utf_8 as the encoding method instead of the default ANSI

2. Open the registry and ensure that the value of hkey_local_machinne/system/CurrentControlSet/services/intinfo/parameters/favordbcs is 0.

3. After modifying the value, you must run iisreset to restart the IIS service.

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.