1. Asp.net:
Response. Cookies ["tcpoauser"]. value = Ds. Tables ["table"]. Rows [0] ["username"]. tostring ();
Request. Cookies ["tcpoauser"]. value. tostring ();
2. Asp.net uses UTF-8 encoding by default, and ASP uses gb2312 encoding. Therefore, a cookie can be shared with each other and must be encoded in the same way.
In Asp.net, if you want to modify the encoding of the output page, you can modify the following configuration information in Web. config:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
The above only modifies the overall default encoding. If only the encoding of a page needs to be modified, Asp.net can simply use the following code:
Encoding gb2312 = Encoding.GetEncoding("gb2312");Response.ContentEncoding = gb2312;
In non-Asp.net applications, the data you may read is UTF-8 encoding, but to convert to gb2312 encoding, you can refer to the following code:
String utfinfo = "document. Write (/" alert ('aa, are you okay ?? ');/");"; String gb2312info = string. empty; encoding utf8 = encoding. utf8; encoding gb2312 = encoding. getencoding ("gb2312"); // convert the string into a byte []. byte [] unicodebytes = utf8.getbytes (utfinfo); // perform the conversion from one encoding to the other. byte [] asciibytes = encoding. convert (utf8, gb2312, unicodebytes); char [] asciichars = new char [gb2312.getcharcount (asciibytes, 0, asciibytes. length)]; gb2312.getchars (asciibytes, 0, asciibytes. length, asciichars, 0); gb2312info = new string (asciichars );