菜菜鸟问题:vs2003为什么不能显示cookie的中文?
本人是超菜鸟,有这样两段代码用于存放和显示cookie,却在win2003server不能显示,不知为什么:
1、
HttpCookie cookie=new HttpCookie( "mycookie ");
cookie.Values.Add( "dept ",DropDownList1.SelectedValue);
cookie.Expires=DateTime.Now.AddMonths(1);
Response.Cookies.Add(cookie);
Response.Redirect( "xxx.aspx ",true);
2、
private void Page_Load(object sender, System.EventArgs e)
{// 在此处放置用户代码以初始化页面
HttpCookie icookie=Request.Cookies[ "mycookie "];
Label1.Text=icookie.Values[ "dept "];
}
急求答案
------解决方案--------------------Cookie不能保存中文内容,用Url编码一下
------解决方案-------------------- 写入cookies: Response.Cookies[ "cpwd "].Value=System.Web.HttpUtility.UrlEncode(ssUserPassword);
Response.Cookies[ "cpwd "].Expires=DateTime.Now.AddDays(365.00);
读取cookies:
System.Web.HttpUtility.UrlDecode(cpwd.Value.ToString());