Cookie的使用及位置
1、cookie生成文件存放的位置:(某些文件可能被隐藏)
C:\Users\zhangmengting(用户)\AppData\Roaming\Microsoft\Windows\Cookies
2、cookie 的保存
HttpCookie cookie = new HttpCookie("MyCook");//初使化并设置Cookie的名称
DateTime dtime = DateTime.Now;
TimeSpan ts = new TimeSpan(0, 0, 1, 0, 0);//过期时间为1分钟
cookie.Expires = dtime.Add(ts);//设置过期时间
cookie.Values.Add("userid", this.userName.Text); //设置cookie产生的键值对
Response.AppendCookie(cookie);
3、cookie的调用
if (Request.Cookies["MyCook"]!=null && Request.Cookies["MyCook"]["userid"] != null)
{
//Response.Write("Cookie中键值为userid的值:" + Request.Cookies["MyCook"]["userid"]); //整行
//Response.Write("Cookie中键值为userid2的值" + Request.Cookies["MyCook"]["userid2"]);
userName.Text = Request.Cookies["MyCook"]["userid"];
//userName.Text = Request.Cookies["MyCook"];//所有键值对
//Response.Write(Request.Cookies["MyCook"].Value);//输出全部的值
}