c# – 异步电子邮件发送未返回视图
发布时间:2020-12-15 22:25:33 所属栏目:百科 来源:网络整理
导读:我的 Asp.net网站上的忘记密码电子邮件链接有问题. 基本上,一切正常,它发送一个电子邮件到帐户,密码可以重置,但我收到404错误,而不是返回正确的页面. public async TaskActionResult ForgotPassword(ForgotPasswordViewModel model){ if (ModelState.IsValid
|
我的
Asp.net网站上的忘记密码电子邮件链接有问题.
基本上,一切正常,它发送一个电子邮件到帐户,密码可以重置,但我收到404错误,而不是返回正确的页面. public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindByEmailAsync(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");
}
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
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);
}
我认为这是一个问题: await UserManager.SendEmailAsync(user.Id,"Please reset your password by clicking <a href="" + callbackUrl + "">here</a>"); 没有这一行,它会返回正确的视图,但显然电子邮件不会发送. 有人遇到过这种情况么? 提前致谢 注:如果模型为null,则返回正确的视图 编辑:身份信息 public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
var mailMessage = new MailMessage("Email here",message.Destination,message.Subject,message.Body
);
var client = new SmtpClient();
client.SendAsync(mailMessage,null);
return Task.FromResult(0);
}
解决方法
在电子邮件部分,您应该收到此错误“在异步操作仍处于挂起状态时完成异步模块或处理程序”.我相信你有404是因为可能没有找到错误页面.
您可以尝试以下方法 public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
var mailMessage = new MailMessage("Email here",message.Body
);
var client = new SmtpClient();
return client.SendMailAsync(mailMessage);
}
或者使用await / async方式 public async Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
var mailMessage = new MailMessage("Email here",message.Body
);
var client = new SmtpClient();
await client.SendMailAsync(mailMessage);
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 给Oracle的数据添加默认值
- .net – 错误:无法加载文件或程序集“ExcelAddIn1.XmlSeri
- ruby-on-rails – 你如何在Mac上更改Rails版本?
- 如何创建用于OpenCV的Haar Cascade(xml)?
- C++ STL容器stack和queue详解
- c – 漫长的VS 2013 Release Win 64错误的结果
- ruby – 在Nokogiri中.at_css到.css之间有什么区别?
- SSE内在函数:测试所有0或1的最快方法?
- c – 这个头的意思是什么(virtual const char * what()cons
- 使用decimal.tryparse的C#千位分隔符问题
