ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,532 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
when signed HttpContext.SignInAsync(claimsPrinciple);
when I close the browser the cookie is not valid and I need login again.
builder.Services.AddAuthentication("Cookie").AddCookie("Cookie", options =>
{
options.Cookie.Name = "j.Cookie";
options.LoginPath = "/Login";
options.ExpireTimeSpan = TimeSpan.FromDays(7);
});
You are using the wrong SignInAsync() overload. Use the SignInAsync() method overload that lets you set the authentication properties. Please see the reference documentation and select the options that best fit your needs.
Use cookie authentication without ASP.NET Core Identity
var authProperties = new AuthenticationProperties
{
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
IsPersistent = true
};
await HttpContext.SignInAsync(
new ClaimsPrincipal(claimsIdentity),
authProperties);