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

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

问题描述

我使用以下代码设置Cookie过期:

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





$ b b

当我读取其他页面中的cookie超时时,我得到1/1/0001 12:00 AM。如果有人可以帮助我弄清楚这个问题,我会很感激。我使用ASP.NET 3.5


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

确定。在阅读来自Gulzar的链接后,似乎我不能检查在HttpRequest上的cookie.Expires?因为链接似乎建议cookie.Expires总是设置为DateTime.MinValue,因为服务器永远不能知道在客户端机器上的实际时间?所以这意味着我必须将时间存储在cookie内部并检查吗?我的理解是否正确?

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?

感谢
Shankar

thanks Shankar

推荐答案

您使用哪个版本的asp.net?这在 asp.net论坛中讨论过。

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天全站免登陆