如何读取cookie创建日期(不是过期) [英] How to read the cookie creation date (not expiration)

查看:201
本文介绍了如何读取cookie创建日期(不是过期)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法来存储在变量中的cookie创建日期?我使用jquery.cookie插件。如果没有办法,我正在考虑存储在cookie中,作为值,实际时间/日期。这可能是一个解决方案。

Is there a way to store in a variable a cookie creation date? I'm using the jquery.cookie plugin. If there is not a way, I'm thinking about store in the cookie, as value, the actual time/date. It could be a solution.

谢谢。

推荐答案

<!-- Output the DateTime that the cookie is set to expire -->
@Request.Cookies["YourCookie"].Expires.ToString()

我不相信有一个属性来获取创建日期,除非你专门存储值本身作为一个额外的价值在Cookie本身:

However, I don't believe that there is a property to get the Creation Date, unless you were to specifically store the value itself as an additional value within the Cookie itself :

//Create your cookie
HttpCookie yourCookie = new HttpCookie("Example");
//Add an actual value to the Values collection
yourCookie.Values.Add("YourValue", "ExampleValue");
//Add a Created Value to store the DateTime the Cookie was created
yourCookie.Values.Add("Created", DateTime.Now.ToString());
yourCookie.Expires = DateTime.Now.AddMinutes(30);

//Add the cookie to the collection
Request.Cookies.Add(yourCookie);

您可以通过以下方式访问您的信息页:

which you could access in your page through :

Created : @Request.Cookies["Example"].Values["Created"].ToString()
Expires : @Request.Cookies["Example"].Expires.ToString()

这篇关于如何读取cookie创建日期(不是过期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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