the error i recive when log me out in asp.net core authentication
Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted. ---> System.Security.Cryptography.CryptographicException: The key {xxxxx} was not found in the key ring.
I use cookie authentication
the controller
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel login, string redirectUrl = null)
{
var user = await GetUserByCredentials(login.UserName, login.Password);
await UpdateLoginDate(user);
var claimsIdentity = new ClaimsIdentity(
authenticationType: CookieAuthenticationDefaults.AuthenticationScheme
);
claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, user.Role));
claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Code));
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
var authProperties = new AuthenticationProperties
{
IsPersistent = login.RememberMe
};
await HttpContext.SignInAsync(
scheme: CookieAuthenticationDefaults.AuthenticationScheme,
principal: claimsPrincipal,
properties: authProperties);
return LocalRedirect(redirectUrl ?? "/");
}
the configuration in startup
services.AddAuthentication(
defaultScheme: CookieAuthenticationDefaults.AuthenticationScheme
).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
//Modifichiamo qui le opzioni di emissione dei cookie
options.ExpireTimeSpan = TimeSpan.FromDays(7);
options.Cookie.Expiration = TimeSpan.FromDays(7);
options.SlidingExpiration = false;
options.LoginPath = new PathString("/Authentication/Login");
});
what is my error? how can solve?
why the expiration cookie not work?