public async Task <IActionResult> OnPostAsync() { var user = await _userManager.GetUserAsync(User); if (user == null) { var msg = _loc.GetLocalizedString(culture, "Unable to load user with ID '{0}'.", _userManager.GetUserId(User)); return(NotFound(msg)); } RequirePassword = await _userManager.HasPasswordAsync(user); if (RequirePassword) { if (!await _userManager.CheckPasswordAsync(user, Input.Password)) { var msg = _loc.GetLocalizedString(culture, "Incorrect password."); ModelState.AddModelError(string.Empty, msg); return(Page()); } } var result = await _userManager.DeleteAsync(user); var userId = await _userManager.GetUserIdAsync(user); if (!result.Succeeded) { throw new InvalidOperationException($"Unexpected error occurred deleting user with ID '{userId}'."); } await _dbContext.RemoverAlunoAsync(user.Id); await _signInManager.SignOutAsync(); _logger.LogInformation("User with ID '{UserId}' deleted themselves.", userId); //return Redirect($"~/{culture}"); return(Redirect("~/")); }