cookie

代码如下:

       //设置httpcookie    
        HttpCookie cscok = new HttpCookie("ckall");
        cscok.Values.Add("uname", "1111111");                //uname为变量名,1111111为变量的值
        cscok.Values.Add("upwd", "2222");                        //同上解释
        cscok.Expires = DateTime.MaxValue;                      //设置httpcookie集合的过期时间
        Response.AppendCookie(cscok);                            //写入httpcookie 类中

        //获取httpcookie
        HttpCookie hqcok = Request.Cookies["ckall"];         //获取httpcookie类集合
        if (hqcok != null)                                                       //判断是否为空
        {
            Response.Write(hqcok.Values["uname"].ToString());
            Response.Write(hqcok.Values["upwd"].ToString());

            //下面是清除httpcookie类集合

            hqcok.Expires = DateTime.Now.AddMinutes(-1);     //设置httpcookie的过期时间为-1
            Response.AppendCookie(hqcok);                            //将设置的过期值写入httpcookie从而清除类值
        }
        else
        {
            Response.Write("没有设置cookies值");
        }

posted @ 2009-07-06 11:06  Rhythmk  阅读(193)  评论(0编辑  收藏  举报
Rhythmk 个人笔记