asp.net之cookie

1.创建cookie

HttpCookie userCookie = new HttpCookie("userInfo");
userCookie["name"] = Request.Form["username"].ToString();
userCookie["pwd"] = Request.Form["pwd"].ToString();
userCookie.Expires = DateTime.Now.AddHours(1);  //设置过期时间
Response.SetCookie(userCookie);

2.获取cookie

Request.Cookies["userInfo"]["name"].ToString();

 

posted @ 2017-10-04 12:45 fight139 阅读(...) 评论(...) 编辑 收藏