CMSCookieLevel

Theodoulos Iacovou asked on January 29, 2020 12:53

Hello guys,

How can i change the CMSCookieLevel (Expires/Max age) from 1 year to 90 days.

Thank you

Recent Answers


Dat Nguyen answered on January 29, 2020 18:50

In code, try this:

HttpCookie cookie = Request.Cookies["CMSCookieLevel"];
if (cookie != null)    
{

    // update the expiration timestamp
    cookie.Expires = DateTime.UtcNow.AddDays(90);

    // overwrite the cookie
    Response.Cookies.Add(cookie);
}
0 votesVote for this answer Mark as a Correct answer

Dmitry Bastron answered on January 29, 2020 19:18

Be extra carefull with Dat's code example provided. If you do this in MVC application code this will disable output cache implicitly (refer here or google more this topic).

0 votesVote for this answer Mark as a Correct answer

Theodoulos Iacovou answered on January 30, 2020 08:20

If i will add this code in global.asax it will work?

0 votesVote for this answer Mark as a Correct answer

Dat Nguyen answered on January 30, 2020 11:36

Better to use the code in a custom module class. Probably in the event handler code for the ApplicationEvents.SessionStart or ApplicationEvents.SessionEnd events. I can't say for sure when Kentico overwrites the cookie itself. You'd have to experiment and see what works.

0 votesVote for this answer Mark as a Correct answer

Theodoulos Iacovou answered on January 30, 2020 12:06

Are you suggested me to use 1 year or 90 days?

0 votesVote for this answer Mark as a Correct answer

Dat Nguyen answered on January 30, 2020 12:10

That's up to you. What's your reasoning for wanting to reduce it to 90 days?

0 votesVote for this answer Mark as a Correct answer

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