JavaScript and dynamic pages cannot get the time the cookie expires, the browser manages the expiration time, and JavaScript and dynamic pages can only set expiration time. cannot be obtained through Document.cookie (JavaScript) or Cookie.expires (asp.net) properties.
The
code is as follows:
<% @page language= "C #" debug= "true"%>
<script runat= "Server" >
protected void Page_Load (object sender, EventArgs e)
{
HttpCookie HC = request.cookies["abc"];
if (HC!= null)
{
Response.Write (HC. Expires);//0001-1-1 0:00:00
Response.End ();
}
}
</script>
asp.net cookies have expires properties, but Response.Write output expires property is 0001-1-1 0:00:00 (Datetime.minvalue), this is because the browser does not send a cookie expiration time to the server, so use Datetime.minvalue to populate the cookie expires properties.
Be sure to get an expiration date, and you need to record the expiration time for the cookie by using another cookie value. As follows:
The
code is as follows:
<script>
var d = new Date ();
d.sethours (d.gethours () + 1); 1 Childhood expired
document.cookie = ' testvalue=123;expires= ' + d.togmtstring (); Store Cookie Value
document.cookie = ' testexp= ' + Escape (d.tolocalestring ()) + '; expires= ' + d.togmtstring (); Store cookie expiration time, to get the expiration time of TestValue this cookie, by obtaining testexp this cookie to implement
</script>