Kartik Patel
Kartik Patel

Reputation: 9603

cookie.Expire is not working in chrome

Hi i come across very strange Problem in chrome.I have following code for Cookie.

 HttpCookie cookie = new HttpCookie("cookie");
 cookie.Value = "true";
 cookie.Expires.AddDays(30);
 Response.Cookies.Add(cookie);

Now above code is not working in chrome while its working well in FF and IE.If i check this cookie in chrome then its there but cookie Expire date is like When the browsing session ends in chrome.

that means if i Close the Browser then the cookie will expire instead of expiring after 30 days.

Upvotes: 4

Views: 4194

Answers (1)

Adam K Dean
Adam K Dean

Reputation: 7475

You have to use DateTime.Now/DateTime.UtcNow:

HttpCookie cookie = new HttpCookie("cookie");
cookie.Value = "true";
cookie.Expires = DateTime.UtcNow.AddDays(30);
Response.Cookies.Add(cookie);

Upvotes: 4

Related Questions