How to read cookie creation date (does not expire)

Is there a way to store the cookie creation date in a variable? I am using jquery.cookie plugin. If there is no way, I think of the store in the cookie as the value, the actual time / date. It may be a solution.

Thanks.

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

However, I do not think that there is a property to get the creation date, unless you have to specifically store this value as an additional value inside 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 can be accessed on the page:

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

You really need to save the time in the cookie itself. The browser cookie API does not provide the creation date as metadata.

+5
source

Source: https://habr.com/ru/post/949737/


All Articles