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 you want to pass Chinese parameters to the. Aspx file from the. HTML file(That is, do not use the Redirect () method for Url conversion 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/20040603123628 中 ..doc"); '> 20040603123628 transaction center online centralized transaction system contract </a>The current location is saved without blinking.<A href = "#" onclick = javascript: change_url ("css/20040603123628 centralized transaction system contract on the tobacco leaf network")> 20040603123628 transaction center online centralized transaction system contract </a> note: the diagonal lines in the path are: "/" instead of "\". Otherwise, it won't work. ----------------------------------------
When I was developing a. net Web, I encountered a very strange problem, that is, in the Url, if the Chinese character is passed as the parameter value, the value of QueryString may be wrong. To put it simply, for example, the following Url:
UrlParmTest. aspx? Parm1 = China & parm2 = Chinese
In Request. QueryString, parm1 and parm2 get both "China". Obviously there is a problem, but in some cases it is normal.
If the request uses Response. Redirect instead of a URL, no similar problems have been encountered.
At that time, I thought that the Chinese language was double-byte encoding. It was possible that there was uncertainty when it was passed, but it was still good to use English.
But why is Redirect on the Server normal? Where is the problem?
:
If you set Chinese parameters in the. cs file, Encode the Chinese parameters using Server. UrlEncode ("Chinese ").
Use<% = Server. UrlEncode ("Chinese") %>Encode
When QueryString is used, Decode is not required to obtain a normal Chinese string.
The following are some explanations:
UrlEncode converts several multi-byte characters into the single-byte characters allowed in the url, which will be automatically implemented by the browser. However, there are some problems, so Encode it yourself, the receiver automatically performs Decode on the Url.
I think Response. Redirect may be able to ensure the work of The Encode, so there is no problem.