The configuration is the same in Web.comfig:
<globalization requestencoding= "gb2312" responseencoding= "gb2312"/>
The header section of the page also has
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
It's strange,
Had to use the stupid way:
Write Parameters:
Copy Code code as follows:
String strURL = Preurl + "? Word={0}&sort={1}&check={2}";
strURL = string. Format (strURL, Httputility.urlencode (This.txtSearchTxt.Text.Trim (), System.Text.Encoding.GetEncoding ("GB2312")), This.radioSortDesc.SelectedIndex.ToString (), checkstate.tostring ());
Page.Response.Redirect (strURL);
Note that the encoding method is gb2312
Read parameters:
Copy Code code as follows:
Try
{if (page.request.querystring["word"]!= null)
{_word = convert.tostring (Httputility.urldecode (page.request.querystring["word"), System.Text.Encoding.GetEncoding ("GB2312")); }
}
catch {_word = String.Empty;}
Note that the encoding is gb2312, corresponding to the preceding
Later, read Mencius's article, only to find a better solution:
With javascript!
Write a method on the base class page
Copy Code code as follows:
public void Pagelocation (string chineseurl)
{
if (Chineseurl==null | | Chineseurl.trim (). length==0)
{return;//also may not be a valid URL for Tony 2007/11/15
}
Page.ClientScript.RegisterStartupScript (this. GetType (), "Agronetpagelocationto", "<script type= ' text/javascript ' language= ' JavaScript ' > Window.location.href= ' "+chineseurl+" ';</script> ");
}
And then call in the page
Copy Code code as follows:
String strURL = Preurl + "? Word={0}&sort={1}&check={2}";
strURL = string. Format (strURL, This.txtSearchTxt.Text.Trim (), this.radioSortDesc.SelectedIndex.ToString (), checkstate.tostring ()) ;
Pagelocation (strURL);
Note that the latter method used Javasrcipt, the actual application in the paging need to maintain Chinese parameters, preferably with window. Location.href Method!
Finally, if you want to have a conversation in JavaScript with the. NET background code, you can do this:
Copy Code code as follows:
<script language= "JavaScript" >
function Gourl ()
{
var Name = "Chinese parameter";
Location.href = "B.aspx?" Name= "+escape (Name);
}
</script >
<body onclick= "Gourl ()" >
Receive:
Copy Code code as follows:
String Name = request.querystring["name"];
Response.Write (Httputility.urldecode (Name));
The main points are:
The passed Chinese parameters are encoded and then decoded at the time of receipt.
Finish.