Change cookie time for "cart"

I was able to get the cart to be saved in a long lived cookie with help of this.

But is it possible to change the time on the “cart” cookie? a customer wants shorter time.

Litium version: 8

I haven’t tested but maybe you can modify that with the OnAppendCookie method that you can configure in Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
                options.Secure = CookieSecurePolicy.SameAsRequest;

                // Change the time on the cookes that are set
                options.OnAppendCookie = ctx =>
                {
                    if (ctx.CookieName.Equals("cart"))
                    {
                        ctx.CookieOptions.Expires = DateTimeOffset.UtcNow.AddHours(6);
                    }
                };
            });
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.