我的重置密码功能已停止工作,我不知道我做了什么,因为它昨天正常工作。
我可以点击我在电子邮件中收到的链接然后我到达asp.net错误页面
找不到UserId。 System.InvalidOperationException:找不到UserId。
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
ApplicationUser user = manager.FindByName(Email.Text);
if (user == null || !manager.IsEmailConfirmed(user.Id))
{
FailureText.Text = "Användaren existerar inte eller så är inte användarkontot bekräftat, bekräfta konto och försök sedan igen.";
ErrorMessage.Visible = true;
ConfirmAccount.Visible = true;
return;
}
string code = manager.GeneratePasswordResetToken(user.Id);
string callbackUrl = IdentityHelper.GetResetPasswordRedirectUrl(code, Request);
manager.SendEmail(user.Id, "Återställ Lösenord", "Återställ lösenord klicka <a href=\"" + callbackUrl + "\">Här</a>.");
电子邮件
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("email");
msg.To.Add(new MailAddress(message.Destination));
msg.Subject = message.Subject;
msg.Body = message.Body;
var smtpClient = new SmtpClient();
smtpClient.EnableSsl = false;
return smtpClient.SendMailAsync(msg);
}
catch (Exception ex)
{
throw ex;
}
}
}
EmailConfirmation几乎相同并且正在运行:
string code = manager.GenerateEmailConfirmationToken(user.Id);
string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
manager.SendEmail(user.Id, "Bekräfta ditt konto", "Bekräfta genom att klicka <a href=\"" + callbackUrl + "\">Här</a>.");