我在服务器上添加 cookie:
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);
}
但是当我从请求中读取 cookie - cookie.Expire 等于日期 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;
}
}
日志:COOKIE.Name:wmpayment COOKIE.Value:0 COOKIE.Expire:01.01.0001 0:00:00 我不明白是什么问题。