ASP.NET Cookie过期时间总是1/1/0001 12:00 AM [英] ASP.NET cookie expiration time is always 1/1/0001 12:00 AM

查看:167
本文介绍了ASP.NET Cookie过期时间总是1/1/0001 12:00 AM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code设置cookie有效期:


  //删除现有的cookie。
request.Cookies.Clear();
response.Cookies.Clear();// ...序列化和加密我的数据?//现在设置cookie。
的HttpCookie饼干=新的HttpCookie(AuthCookieName加密);
cookie.Expires = DateTime.Now.Add(TimeSpan.FromHours(CookieTimeOutHours));
cookie.HttpOnly = TRUE;
response.Cookies.Add(饼干);//重定向到另一个页面


当我在其他页面读取cookie超时我越来越1/1/0001上午12:00。如果有人可以帮我找出这个问题,我会AP preciate它。我使用ASP.NET 3.5

确定。从古勒扎尔阅读链接后,看来我不能在Htt的prequest检查cookie.Expires呢?因为链接似乎表明,cookie.Expires总是被设置为DateTime.MinValue因为服务器可以永远不知道在客户机上的实际时间?因此,这意味着我有时间存储的cookie里面自己和检查呢?是我的理解是否正确?

谢谢
尚卡尔


解决方案

您正在使用哪个版本的asp.net的?这在 asp.net论坛讨论。<​​/ P>

I'm setting the cookie expiration using the following code:


// remove existing cookies.
request.Cookies.Clear();
response.Cookies.Clear();

// ... serialize and encrypt my data ...

// now set the cookie.
HttpCookie cookie = new HttpCookie(AuthCookieName, encrypted);
cookie.Expires = DateTime.Now.Add(TimeSpan.FromHours(CookieTimeOutHours));
cookie.HttpOnly = true;
response.Cookies.Add(cookie);

// redirect to different page


When I read the cookie timeout in the other page I'm getting 1/1/0001 12:00 AM. If someone can help me figure out the problem, I'll appreciate it. I'm using ASP.NET 3.5

ok. after reading the links from Gulzar, it appears that I cannot check cookie.Expires on the HttpRequest at all? Because the links seem to suggest that cookie.Expires is always set to DateTime.MinValue because the server can never know the actual time on the client machine? So this means I have to store the time inside the cookie myself and check it? Is my understanding correct?

thanks Shankar

解决方案

Which version of asp.net are you using? This was discussed in asp.net forum.

这篇关于ASP.NET Cookie过期时间总是1/1/0001 12:00 AM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆