public async Task <IActionResult> OnPostAsync(string returnUrl = null) { ReturnUrl = returnUrl ?? "/Admin"; if (ModelState.IsValid) { var user = await _dbHelper.AuthenticateUser(UserName, Password); if (!user) { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(Page()); } var claims = new List <Claim> { new Claim(ClaimTypes.Name, UserName), new Claim(ClaimTypes.Role, "Admin") }; var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity)); return(RedirectToPage(ReturnUrl)); } // Something failed. Redisplay the form. return(Page()); }