C # URL-based Chinese parameter transfer solution

Source: Internet
Author: User

1. Set the web. config file.
<System. web>

<Globalization

RequestEncoding = "gb2312" responseEncoding = "gb2312" culture = "zh-CN" fileEncoding = "gb2312"/>

</System. web>

Or:
In the aspx file:
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">

2. Before passing Chinese characters, encode the Chinese parameters to be passed and decode them upon receiving them.
> Transfer

String Name = "Chinese parameter ";

Response. Redirect ("B. aspx? Name = "+ Server. UrlEncode (Name ));

> Receive

String Name = Request. QueryString ["Name"];

Response. Write (Server. UrlDecode (Name ));
Or:

NavigateURL = <% # "WebForm2.aspx? Singer = "+ HttpUtility. UrlEncode (" Chinese ", System. Text. Encoding. GetEncoding (" GB2312 ") %>

3. If a Chinese parameter is transferred from the. HTML file to the. Aspx file (that is, Url conversion is not performed using the Redirect () method from the background ). Similarly, the passed Chinese parameters must be encoded and decoded upon receiving.

> Transfer

<Script language = "JavaScript">

Function GoUrl ()
{
Var Name = "Chinese parameter ";

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

}
</Script>
<Body onclick = "GoUrl ()">

> Receive

String Name = Request. QueryString ["Name"];

Response. Write (Server. UrlDecode (Name ));

In general. Set the web. config file. However, if you use JavaScript to call the webservice method (passing Chinese parameters to webservice ). The web. config file is invalid.

--------------------
Codec in html:

<Script language = "javascript">

Function openurl (/src)
{
Var strUrl = escape (src );
Window. open (strUrl );
}

Function change_url (/src)
{
Document. location. href = "/escape" (src );
}

</Script>

Save in new window
<A href = javascript: openUrl ("css/Contract .doc");> submit the contract </a>

The current location is saved without blinking.
<A href = "#" onclick = BLOCKED SCRIPTchange_url ("css/Contract .doc")> contract </a>

Note: The slash in the path is "/" instead of "". Otherwise, it will not work.

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.