public void setCookies()
{
HttpCookie ck = new HttpCookie("loginfo");
ck.Values.Add("username",userName);
ck.Values.Add("userpasswd",passWd);
ck.Values.Add("autolog",(autoLog.ToString()));
ck.Expires = DateTime.MaxValue;
HttpContext.Current.Response.Cookies.Add(ck);
}
#endregion
#region readCookie()
/// <summary>
/// 读取Cookie
/// </summary>
/// <returns></returns>
public void readCookie()
{
HttpCookie ck = HttpContext.Current.Request.Cookies["loginfo"];
if (ck != null)
{
userName = Convert.ToString(ck.Values["username"]);
passWd = Convert.ToString(ck.Values["userpasswd"]);
autoLog = Boolean.Parse(ck.Values["autoLog"]);
}
}
#endregion
}
在浏览器中存的Cookie是username=雷亚辉&userpasswd=lyh12063259&autolog=True
读出来的结果是usename 为乱码,userpasswd="",autolog=""
大叔好逗啊,谢谢大叔,