创建Cookie 时候必须命名全部路径
View Code
1 HttpCookie UserCookie = new HttpCookie("User");
2 UserCookie["UserID"] = 1;
3 System.Web.HttpContext.Current.Response.Cookies.Add(UserCookie);
2 UserCookie["UserID"] = 1;
3 System.Web.HttpContext.Current.Response.Cookies.Add(UserCookie);
获取Cookie值
View Code
1 HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["User"];
2 string id = cookie.Values["UserID"];
2 string id = cookie.Values["UserID"];