读写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("<a href='readcookie.ashx'>读cookie</a>");  
   读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  木屐  阅读(85)  评论(0编辑  收藏  举报

导航