Commander
Commander
CC#
Created by Commander on 3/13/2024 in #help
.NET 8 Simple Cookie Authentication
Hello, I am a bit confused about simple Cookie Authentication in .net 8 I have the following in my Program.cs:
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromHours(Constants.LoginTimeoutHours);
options.Cookie.IsEssential = true;
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.None; // will make it SSL later
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.Name = "somename";
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = "/Home/AccessDenied";
});
...
app.UseAuthentication();
app.UseAuthorization();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromHours(Constants.LoginTimeoutHours);
options.Cookie.IsEssential = true;
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.None; // will make it SSL later
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.Name = "somename";
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = "/Home/AccessDenied";
});
...
app.UseAuthentication();
app.UseAuthorization();
3 replies