当用户与生成的令牌一起注册时,我正在尝试发送确认电子邮件。令牌没问题。但是在发送电子邮件时,我收到此错误:
System.NotSupportedException: Store does not implement IUserEmailStore<TUser>.
我在 AccountController 中的 Register 方法中的代码如下所示: 导致错误的是 SendEmailAsync() 方法:
if (result.Succeeded)
{
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
ViewBag.Link = callbackUrl;
return View("DisplayEmail");
}
在我的 IdentityConfig.cs 文件中,我有一个类:
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}
}
同样在我的 IdentityConfig.cs 文件中,我还有另一个类:
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
SmtpClient client = new SmtpClient();
return client.SendMailAsync(ConfigurationManager.AppSettings["TranscriptEmailAddr"],
message.Destination,
message.Subject,
message.Body);
}
}
请协助。