【发布时间】:2016-08-28 18:13:41
【问题描述】:
我的忘记密码方法有一个问题,虽然它的状态=RantoCompletion 但根本没有收到电子邮件。我已经尝试了很多电子邮件地址,但什么都没有。谁能告诉我可能是什么问题。 这是代码:
// POST: /Account/ForgotPassword
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByNameAsync(model.Email);
if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
{
// Don't reveal that the user does not exist or is not confirmed
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");
}
// If we got this far, something failed, redisplay form
return View(model);
}
这是我的调试图像:
【问题讨论】:
-
您如何配置您的电子邮件设置?你用什么smtp服务器?出于故障排除的目的,请尝试
UserManager.SendEmail(而不是 Async 版本...这样更容易调试。 -
对不起,我刚接触asp.net,我不知道怎么知道。你能告诉我吗?
标签: c# asp.net-mvc