Set cookie that expires at end of session

Alexander Toups asked on October 15, 2015 14:59

Is there a way to make a cookie set with:

CookieHelper.SetValue

to expire by end of the session instead of prividing an exire date?

Recent Answers


Maarten van den Hooven answered on October 16, 2015 09:09

Hi Alexander why don't you use the SessionHelper if you only want to store you're data in the session.

https://devnet.kentico.com/docs/8_2/api/html/M_CMS_Helpers_SessionHelper_SetValue.htm

If you use an older Kentico version it is : CMS.GlobalHelper.SessionHelper

Good luck!!!!

0 votesVote for this answer Mark as a Correct answer

Alexander Toups answered on October 16, 2015 09:43

Hi Maarten, Thanks for the idea. I'm using cookies because I need to read them as well with JQuery.

Thanks. Alex.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on October 16, 2015 10:30

Ok if you need the cookie in your jQuery then you cannot use session because that's only server side.

I would consider to use the ASP.NET Response.Cookies and Request.Cookies instead of the CookieHelper. (that what I did in previous projects)

For more information see ASP cookies on W3Schools or ASP.NET Cookies Overview on MSDN

And if you don't set any expires value, it will expire after the end of the session automatically. See also this stackoverflow questions : set cookie to expire at end of session? asp.net

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.