asp.net|cookie| Chinese Characters | solving
Today, a student sister asked me: In the asp.net HttpCookie write Chinese characters, read the value of why are all garbled? In fact, this is because of the text encoding, the Chinese character is two code, so it will get out of such a garbled! In fact, the solution is very simple: as long as the cookie is written, the first URL code, and then write, when we read and then decode the OK, hope that more students sister can solve it, hehe!
Example:
Write to Cookie:
1HttpCookie cookie=new HttpCookie ("simple");
2cookie. Values.add ("Simple1", Httputility.urlencode ("Uncle, Hello!") "));
3cookie. Values.add ("Simple2", "中文版 is ok! Nothing we should do! ");
4response.appendcookie (cookie); Read the cookie:
1HttpCookie cookie=request.cookies["Simple"];
2string Simple1=httputility.urldecode (cookie["Simple1"]);
3string simple2=cookie["Simple2"]; So simple1= "uncle, Hello!" '; simple2= ' Chinese is ok! Nothing we should do! ";
It's very simple!!!