During ASP. NET development, page garbled characters are frequently encountered. For details, refer:
Solve Chinese garbled ASP. NET Method There are generally four types:
ASP. NET Chinese garbled characters Solution 1. Set the Web. config file
<System. Web>
......
<Globalization requestencoding = "gb2312" responseencoding = "gb2312" Culture = "ZH-CN" fileencoding = "gb2312"/>
......
</System. Web>
ASP. NET Chinese garbled solution 2. encode the Chinese parameters to be passed before passing the Chinese characters 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 ));
ASP. NET Chinese garbled solution 3. If a Chinese parameter is transferred from the. html file to the. aspx file (that is, URL conversion is not performed from the background using the Redirect () method ). 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 );
}
<Body onclick = "gourl ()">
> Receive
String name = request. querystring ["name"];
Response. Write (server. urldecode (name ));
Another method is to encode the code as long as it is transmitted, and it will automatically help you decode it when it is obtained!
> Transfer
String name = "Chinese parameter ";
Response. Redirect ("B. aspx? Name = "+ server. urlencode (name ));
Summary of ASP. NET Chinese garbled solutions:
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");
// It is recommended that you obtain Chinese parameters from other pages without garbled characters, it is simpler
string message = "http: // localhost/test/test1.aspx? 111 = "+ system. web. httputility. urlencode ("People's Republic of China");
HTTP:
// The address for which you want to obtain the return value of a page "
// send a request
httpwebrequest myhttpwebrequest = (httpwebrequest) webrequest. create (Message);
// accept the 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 output to the page
returnvalue = readstream. readtoend ();