C#C
C#4y ago
no >> body

OnAppendCookie callback doesn't work

I have an ASP.NET Core project, which uses IdentityServer4. In my configuration I have CookiePolicyOptions which contains the next setup:

services.Configure<CookiePolicyOptions>(
    option =>
    {
        option.MinimumSameSitePolicy = SameSiteMode.None;
        option.HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always;
        option.OnAppendCookie = cookieContext =>
        {
            Console.WriteLine("Cookie appended: " + cookieContext.CookieName);
        };
        option.OnDeleteCookie = context =>
        {
            Console.WriteLine("Cookie deleted: " + context.CookieName);
        };
    });


For some reason, I can't reach the code from the OnAppendCooie and OnDeleteCookie.
I've also added a custom filter to append a new cookie to the response. The behavior was still the same - OnAppendCookie and OnDeleteCookie were not called.
Was this page helpful?