我该如何设置在用户本地时间Cookie有效期? [英] how do I set cookie expiration time in user local time?

查看:777
本文介绍了我该如何设置在用户本地时间Cookie有效期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个cookie来在10分钟内到期精确(只是为参数的缘故)。

I want a cookie to expire in 10 minutes precisely (just for the sake of argument).

如果我用过期时间=日期时间。 Now.AddMinutes(30)键,用户在我后面3个小时,cookie将尽快,因为它是收到到期(这是正确的?)

If I use Expires = DateTime.Now.AddMinutes(30) and user is 3 hours behind me, cookie will expire as soon as it is received (is this correct?)

我如何设置过期所以它是本地用户?

How do I set expiration so it is local to user?

当然,我可以使用JavaScript来一起发送信息的请求时,或使用一个JS库一些在客户端创建的cookie,或者保留用户的个人资料,并询问用户的时区,但我期待一个懒惰的人的解决方案。

Sure, I can use JavaScript to send that info together with the request, or use a JS-library of some sort to create cookie on the client side, or keep user profile and ask user for time zone, but I am looking a lazy-man solution.

推荐答案

cookie过期日期将最终成为一个GMT时间,所以您的代码将只是工作。

The cookie expiration date will end up as a GMT time, so your code will simply work.

这篇关于我该如何设置在用户本地时间Cookie有效期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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