I’m adding cookie on the server:
private void AddCookie(int id)
{
HttpCookie cookie = new HttpCookie("wmpayment");
cookie.Value = id.ToString();
cookie.Expires = DateTime.Now.AddDays(2);
this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
}
but when I am read cookie from Request – cookie.Expire equals date 01.01.0001
public static int WMPendingOrder
{
get
{
var cookie = HttpContext.Current.Request.Cookies["wmpayment"];
int id = 0;
DateTime exp;
if (cookie != null)
{
DateTime.TryParse(cookie.Expires.ToString(), out exp);
if (DateTime.Now < exp)
int.TryParse(cookie.Value, out id);
}
return id;
}
}
log: COOKIE.Name: wmpayment COOKIE.Value: 0 COOKIE.Expire: 01.01.0001 0:00:00
I am not understand what the problem.
So there are basically two pieces of information you need to persist. The id and an expiry date. How about storing the expiry date in a separate cookie:
So to check the expires date for cookie
wmpaymentyou read the value of cookiewmpaymentexpire.