public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(Input.Email); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) { // Don't reveal that the user does not exist or is not confirmed return(RedirectToPage("./ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please // visit https://go.microsoft.com/fwlink/?LinkID=532713 var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Page( "/Account/ResetPassword", pageHandler: null, values: new { code }, protocol: Request.Scheme); try { var body = "<p> Email From: " + "{0} ({1}) </p> <p>Message:" + "</p><p>{2}</p>"; body = string.Format(body, Input.Email, "Reset Password", $"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); PasswordReset mail = new PasswordReset(); await mail.SendEmailAsync(Input.Email, "Reset Password", body); } catch (Exception ex) { } return(RedirectToPage("./ForgotPasswordConfirmation")); } return(Page()); }