.net 项目中cookie丢失解决办法

时间:2020-12-22 06:14:03

创建cookie的时候

HttpCookie PdaCookie = new HttpCookie("Pda");
PdaCookie ["PdaId"] = 1;
System.Web.HttpContext.Current.Response.Cookies.Add(PdaCookie );

获取的时候

HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["Pda"];
string id = cookie.Values["PdaId"];

删除cookie

HttpCookie cookies = Request.Cookies[cookiename];
            if (cookies != null)
            {
               cookies.Expires = DateTime.Today.AddDays(-1);
               Response.Cookies.Add(cookies);
               Request.Cookies.Remove(cookiename);
            }