public async Task <IActionResult> OnPost() { try { if (ModelState.IsValid) { var user = m_UserSecurity.AuthenticateUserCredentials(UserLogin.LoginID, UserLogin.Password); if (user != null) { var claims = new List <Claim> { new Claim(ClaimTypes.IsPersistent, "false", "bool"), new Claim(ClaimTypes.Name, user.LoginId), new Claim(ClaimTypes.GivenName, user.DisplayName), new Claim("UserId", user.Id.ToString()) }; foreach (var role in user.AppUserRoles) { claims.Add(new Claim(ClaimTypes.Role, role.AppRole.Role)); if (claims.FirstOrDefault(x => x.Type == "Group") == null) { //if (role.AppRole.Role == BeratenHealthcareModels.Roles.Supervisor.ToString()) // claims.Add(new Claim("Group", "Super")); } } HttpContext.Session.SetInt32("UserAuthId", user.Id); var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal); if (user.AppUserRoles.Count() != 0) { return(RedirectToPage(Navigator.Dashboard)); } else { HttpContext.Session.Clear(); //await HttpContext.SignOutAsync(); return(RedirectToPage(Navigator.Login)); } } else { ModelState.AddModelError(string.Empty, "Invalid login attempt. Please try again."); return(Page()); } } else { return(Page()); } } catch (Exception ex) { m_Log.CriticalEntry(User.Identity.Name, ex.ToString()); throw; } }