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();