读写cookie

写cookie
HttpCookie hc = new HttpCookie("username", "xxxx");
hc.Expires = DateTime.Now.AddDays(2);
context.Response.Cookies.Add(hc);

context.Response.Write("写入cookie成功");
context.Response.Write("读cookie");
读cookie
HttpCookie hc = context.Request.Cookies["username"];
if(hc!=null)
{
context.Response.Write("欢迎你" + hc.Value);
}
else
{
context.Response.Write("cookie为空");
}

posted on 2015-01-25 17:34  木屐  阅读(105)  评论(0)    收藏  举报

导航