ASP.net写入和读取Cookies

一、写入:

 HttpCookie cook = new HttpCookie("abcname");
                cook.Expires = DateTime.Now.AddYears(1);//设定过期时间
                cook["username"] = user.Uname;
                Response.Cookies.Add(cook);

二、读取:

            HttpCookie cook = Request.Cookies["abcname"];
            string name = string.Empty;
            if (cook != null)
            {
                name = Convert.ToString(cook["username"]);
            }

 

 

posted @ 2012-12-13 11:28  lhfly  阅读(189)  评论(0编辑  收藏  举报