代码改变世界

C#服务器端读写cookie

2010-09-19 16:22  一片温柔  阅读(371)  评论(0)    收藏  举报

通过js读写cookie,大家都知道,在服务器端,怎么读写cookie呢?

读cookie:

        string cookie = context.Request.Cookies["guid"] == null ? "" : context.Request.Cookies["guid"].Value as string;

写cookie:

         string cookie = Guid.NewGuid().ToString();
         HttpCookie objCookie = new HttpCookie("guid", cookie);
         objCookie.Expires = DateTime.MaxValue;
         context.Response.Cookies.Add(objCookie);

 

keyword:服务器端读写cookie,HttpCookie