简体   繁体   中英

C# asp.net: Cookie Expiration date in Chrome

I'm having an issue with the Expiration date of a cookie in C# when in chrome.

Here is the code I'm using:

public static void createCookie(Users u, DateTime expirationDate)
{
    HttpCookie loginCookie = new HttpCookie("cookie");
    loginCookie.Value = "somevalue";
    loginCookie.Expires = DateTime.UtcNow.AddDays(1d);
    HttpContext.Current.Response.Cookies.Add(loginCookie);
}

I've run this code through Fiddler and it does return the correct Expiration Date. The cookie's expiration date is also correct in Firefox and IE9 However, when I run this in chrome the expiration date is always set to: Sun, 07 Dec 1969 03:28:36 GMT

Always at 3:28:36 GMT it never changes. Any idea on why this is happening would be greatly appreciated. Thanks!

I've also tried to set the expiration date using: DateTime.Now.AddDays(1d) with the same result.

It's a bug in the current version of chrome, it's the displaying of the expiration date that is wrong, not the actual expiration, the value you have set will be honored by chrome!

Here's a link to the bug which has been fixed in their nightly builds (Verified as Fixed with 20.0.1132.7 (Official Build 136817)) : http://code.google.com/p/chromium/issues/detail?id=125546

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM