I'm writing my first ASP.NET 7 app and I'm confused about how cookies are set up. I've read various blogs and tutorials and have gleaned the following information:
Configure the cookie policy and authentication in Program.cs like this:
builder.Services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
builder.Services.AddAuthentication(
CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie();
And add this middleware:
app.UseCookiePolicy(new CookiePolicyOptions { Secure = CookieSecurePolicy.Always, HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always }) ;
From what I can see the cookie policy options are being set twice, with different options? Should it only be done in one place with all the options? Is there a difference in doing it in one place or the other?