Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 574
Gregory Billings Avatar asked Jun 05 '12 00:06

Gregory Billings


1 Answers

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

like image 168
Faraday Avatar answered Sep 28 '22 22:09

Faraday