I have a problem with a password link for a forgotten password on my Asp.net website.
In principle, everything works fine, it sends an email to the account, and the password can get reset, but I get a 404 error, and not return the correct page.
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByEmailAsync(model.Email);
if (user == null)
{
return View("ForgotPasswordConfirmation");
}
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("ForgotPasswordConfirmation", "Account");
}
return View(model);
}
I think this is the problem with this line:
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
Without this line, it will return the correct view, but, obviously, the letter will not be sent. I debugged and passed through it, but could not find any errors.
Has anyone else come across this?
Thank you in advance
Nb if the model is null, it returns the correct form
EDIT: Person Report
public Task SendAsync(IdentityMessage message)
{
var mailMessage = new MailMessage("Email here",
message.Destination,
message.Subject,
message.Body
);
var client = new SmtpClient();
client.SendAsync(mailMessage, null);
return Task.FromResult(0);
}