1. Set the Web.config file. (I don't like to set it up like this)
<system.web>
......
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
......
</system.web>
or: aspx file:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
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)); Or: Navigateurl= ' <%# ' webform2.aspx? Singer= "+ httputility.urlencode (" Chinese ", System.Text.Encoding.GetEncoding (" GB2312 "))%> '
3. If it's from. HTML file to. Aspx file for passing Chinese parameters(That is, the URL conversion is not done from the background with the Redirect () method). 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);
}
</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 use JavaScript to invoke the WebService method (pass the Chinese parameter to the WebService). Setting the Web.config file appears to be invalid.
————————————————————
to implement codecs 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 Trading center tobacco online centralized Trading system contract. Doc"); ' >20040603123628 Trading Center online centralized trading system contract </ A>
the current position is saved without blinking. <a href= "#" onclick= javascript:change_url ("css/20040603123628 Trading center tobacco online centralized Trading system contract. Doc") > 20040603123628 Trading Center Online centralized trading system contract </a> Note: The slash in the path is: "/", not "/" or not. ----------------------------------------
A while ago I encountered a very strange problem when I was doing. NET Web development (I am a. NET novice, so there are more problems), that is, in the URL, if you pass the Chinese character as a parameter value, querystring can get a wrong value. To put it simply, for example, the following URL:
urlparmtest.aspx?parm1= Chinese &parm2= Chinese
In Request.QueryString, Parm1 and Parm2 were both "China", apparently having problems, but in some cases they were normal.
If the request is not directly through the URL and uses Response.Redirect to operate on the server side, no similar problem has been encountered.
At that time, I thought that Chinese is a double-byte code, may be passed when there is uncertainty, or in English good.
But why redirect is normal on the server side, where is the problem?
Yesterday, I asked the students in Gtec to understand some of the following:
If you set the Chinese parameter in the. cs file, use Server.URLEncode ("Chinese") outside the Chinese parameter to encode the Chinese language
If set in the. aspx file, use <%=server.urlencode ("Chinese")%> for Encode
In the QueryString, no more decode, you can get the normal Chinese string
Here are some explanations given by the students:
UrlEncode a number of multibyte characters into the URL allowed single-byte characters, the browser will automatically do, but there are some problems, so I encode again, on the receiving end will automatically decode the URL.
I think Response.Redirect may be able to ensure that encode work, so no problem.