日期:2014-05-19  浏览次数:20483 次

对Cookie的操作不熟,帮我看看这个简单的Cookie吧
我在登录操作中进行了下面的处理
HttpCookie   cookie_year   =   new   HttpCookie(CookiePrefix+ "other_cook ",string.Empty);
cookie_year.Values.Add( "LastLoginTime "   ,LastLoginTime);
cookie_year.Expires   =   DateTime.Now.AddDays(365);
cookie_year.Domain   =   HttpContext.Current.Request.Url.Host;
cookie_year.Path   =   "/ ";
HttpContext.Current.Response.AppendCookie(cookie_year);


我在注销操作中进行了下面的处理
HttpCookie   cookie_year   =   new   HttpCookie(CookiePrefix+ "other_cook ",string.Empty);
cookie_year.Values.Add( "LastLogoutTime "   ,LastLogoutTime);
cookie_year.Expires   =   DateTime.Now.AddDays(365);
cookie_year.Domain   =   HttpContext.Current.Request.Url.Host;
cookie_year.Path   =   "/ ";
HttpContext.Current.Response.AppendCookie(cookie_year);

我发现我登陆之后Cookie文件中就只有LastLoginTime,而注销之后就只有LastLogoutTime
我希望我的代码只是在登录时改写LastLoginTime,注销时改写LastLogoutTime
而不是登录时把LastLogoutTime给弄没了,注销时把LastLoginTime给弄没了


我的代码哪里有问题吗?

------解决方案--------------------
HttpContext.Current.Response.AppendCookie
对于cookie每次 的 操作都是 重写了的

你把logintime先读取出来 注销时候一起存进去就是...

楼主应该不用把代码写出来了吧:)

------解决方案--------------------
写得这么复杂

Reponse.Cookies[ "xxx "].value= "xxxx "

Reponse.Cookies[ "xxx "].express = datetime.now.addday(10) ;大小写请自己改一下


要注销的话直接把它的过期时间改到今天之前.就自动注销了.. 用Remove 方法是错的
------解决方案--------------------
cookie 写的太多了