c# Asp.net getting Cookie expiration time set in javascript always returns 01.01.0001

后端 未结 2 364
萌比男神i
萌比男神i 2021-01-18 00:34

I use a javascript function to store the cookie:

createCookie(\"teaser\", \"teaser\", 7);
function createCookie(name, value, days) {
var expires = \"\";
if (         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 01:06

    The browser does not transmit the expiration date of a cookie to servers, this is as per HTTP specification.

    Browsers only send the cookie name and value only.

    The Expires property on the cookie object is only used when setting expiration date on a cookie that is going to be written in a response, not read in a request.

    When reading the cookie is Expires property value is always going to be null. You can see this for yourself by examining the HTTP headers. If you really want to read the expire value of a cookie, try writing it in the value itself, or using another cookie with the value of the expiration date (you will need to keep them in sync yourself).

提交回复
热议问题