During ASP. NET development, page garbled characters are frequently encountered. The following information is collected on the Internet. For more information, see:
The following reproduced from: http://blog.csdn.net/echsys/archive/2008/03/12/2174125.aspx
There are generally three solutions:
1. Set the Web. config file
< System . Web >
......
< Globalization Requestencoding = "Gb2312" Responseencoding = "Gb2312" Culture = "ZH-CN" Fileencoding = "Gb2312" />
......
</ System. Web >
2. Before passing Chinese characters, encode the Chinese parameters to be passed and decode them upon receiving them.
> Transfer
String Name = " Chinese Parameters " ;
Response. Redirect ( " B. aspx? Name = " + Server. urlencode (name ));
> Receive
String Name = Request. querystring [ " Name " ];
Response. Write (server. urldecode (name ));
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 Parameters " ;
Location. href = " B. aspx? Name = " + Escape (name );
}
< Body onclick = " Gourl () " >
> Receive
String Name = Request. querystring [ " Name " ];
Response. Write (server. urldecode (name ));
Summary:
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.
Or use
Response. Redirect ( " Test1.aspx? 111 = " + System. Web. httputility. urlencode ( " People's Republic of China " ));
// We recommend that you use the final method. If you get Chinese parameters from other pages without garbled characters, it will be simpler.
String Message = " Http: // localhost/test/test1.aspx? 111 = " + System. Web. httputility. urlencode ( " People's Republic of China " );
HTTP:
// You need to obtain the address of the return value of a page"
// Send request
Httpwebrequest myhttpwebrequest = (Httpwebrequest) webrequest. Create (Message );
// Accept request
Httpwebresponse myhttpwebresponse = (Httpwebresponse) myhttpwebrequest. getresponse ();
Stream receivestream = Myhttpwebresponse. getresponsestream ();
Streamreader readstream = New Streamreader (receivestream, system. Text. encoding. getencoding ( " Gb2312 " ));
// This is the returned result of the return value of the page to be retrieved.
Returnvalue = Readstream. readtoend ();
The above is an excerpt from the Internet written to the blog for backup .. (* ^__ ^ *) Xi ......