System.Text.Encoding enc = System.Text.Encoding.GetEncoding("GB2312");
Request.Cookies["YourCookieName"].Value = HttpUtility.UrlEncode("汉字", enc);
Request.Cookies["YourCookieName"].Value = HttpUtility.UrlEncode("汉字", enc);
调试欢乐多
string s = HttpUtility.UrlDecode(Request.Cookies["YourCookieName"].Value, enc)
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("GB2312");
HttpCookie cookie=new HttpCookie("YourCookieName");
string ss = HttpUtility.UrlEncode("也是中文嘛",enc);
cookie.Values.Add("user_name", ss);
System.Web.HttpContext.Current.Response.AppendCookie(cookie);在asp中
<%=Request.Cookies("YourCookieName")("user_name")%>
方法类同思归都是先对string进行编码。
做个测试先。
1新建一个asp页面在body里写上<%=Request.Cookies("YourCookieName")("user_name")%>
2新建一个asp.net页面在Page_Load里写上
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("GB2312");
HttpCookie cookie=new HttpCookie("YourCookieName");
string ss = HttpUtility.UrlEncode("也是中文嘛",enc);
cookie.Values.Add("user_name", ss);
System.Web.HttpContext.Current.Response.AppendCookie(cookie);
3在该asp.net页面中加上到那个asp页面的链接
4生成并浏览该asp.net页面
5点击里面的链接,你应该就会被链到那个asp页面并且将看到"也是中文嘛"这句话。