asp.net-mvcsession-cookies.net-6.0app-startup

SameSite attribute cannot be changed



I've set the `Cookie.SameSite` value to `SameSiteMode.Lax` inside`services.ConfigureApplicationCookie(...)`. Now I'm still getting the cookie with the SameSite value set to strict after I restarted the app and signed in.

services.ConfigureApplicationCookie(...):

services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.Name = "sessionCookie";
                options.Cookie.HttpOnly = true;
                options.Cookie.SameSite = SameSiteMode.Lax;
                options.Cookie.MaxAge = TimeSpan.FromHours(5);
                options.SlidingExpiration = true;
                options.LogoutPath = $"/SignOut";
                options.AccessDeniedPath = $"/Account/AccessDenied";
            });
services.AddDefaultIdentity<ApplicationUser>()
    .AddDefaultUI()
    .AddRoles<ApplicationRole>()
    .AddEntityFrameworkStores<AppIdentityDbContext>();

Solution

  • The problem was the following line of code which came way before the lines shown in the question:

    services.AddCookieConfiguration();

    This was an method with return type IServiceCollection, which was written by another developer a few months ago. Because of this "error" I realized how messy our Startup.cs actually is and extracted some configurations into their own methods.