After a bit of investigation, I found out that the problem is in
Libraries\Nop.Services\Authentication\CookieAuthenticationService.cs at this line await _httpContextAccessor.HttpContext.SignInAsync(NopAuthenticationDefaults.AuthenticationScheme, userPrincipal, authenticationProperties);
How to reproduce
create a few accounts (sometimes it works fine), and make sure you have no breakpoints.
Running webapp with breakpoints before
var authenticationProperties = new AuthenticationProperties
or in other register methods, everything works fine again. The temporary workaround: I use await Task.Delay(1000); before var authenticationPropertiespublic virtual async Task SignInAsync(Customer customer, bool isPersistent)
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));
//create claims for customer's username and email
var claims = new List<Claim>();
if (!string.IsNullOrEmpty(customer.Username))
claims.Add(new Claim(ClaimTypes.Name, customer.Username, ClaimValueTypes.String, NopAuthenticationDefaults.ClaimsIssuer));
if (!string.IsNullOrEmpty(customer.Email))
claims.Add(new Claim(ClaimTypes.Email, customer.Email, ClaimValueTypes.Email, NopAuthenticationDefaults.ClaimsIssuer));
//create principal for the current authentication scheme
var userIdentity = new ClaimsIdentity(claims, NopAuthenticationDefaults.AuthenticationScheme);
var userPrincipal = new ClaimsPrincipal(userIdentity);
await Task.Delay(1000);
//set value indicating whether session is persisted and the time at which the authentication was issued
var authenticationProperties = new AuthenticationProperties
{
IsPersistent = isPersistent,
IssuedUtc = DateTime.UtcNow
};
//sign in
await _httpContextAccessor.HttpContext.SignInAsync(NopAuthenticationDefaults.AuthenticationScheme, userPrincipal, authenticationProperties);
//cache authenticated customer
_cachedCustomer = customer;
}