当前位置: 代码迷 >> ASP.NET >> cookie丢掉
  详细解决方案

cookie丢掉

热度:3567   发布时间:2013-02-25 00:00:00.0
cookie丢失
[NullReferenceException: 未将对象引用设置到对象的实例。]

------解决方案--------------------------------------------------------
HttpCookie MyCookie = new HttpCookie("LastVisit"); 

DateTime now = DateTime.Now; 

MyCookie.Value = now.ToString(); 

MyCookie.Expires = now.AddHours(1); 
Response.Cookies.Add(MyCookie); 

要设置cookie的过期时间,不然下次浏览器关闭后自动过期
  相关解决方案