MVC 中的 ASP.NET Identity IUserEmailStore 错误

Yas*_*utt 2 asp.net-mvc identity usermanager

当用户与生成的令牌一起注册时,我试图发送确认电子邮件。令牌没问题。但是在发送电子邮件时,我收到此错误:

System.NotSupportedException: Store does not implement IUserEmailStore<TUser>.
Run Code Online (Sandbox Code Playgroud)

我在 Register 方法中 AccountController 中的代码如下所示: 导致错误的是 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");
}
Run Code Online (Sandbox Code Playgroud)

在我的 IdentityConfig.cs 文件中,我有一个类:

public class ApplicationUserManager : UserManager<ApplicationUser>
{
        public ApplicationUserManager(IUserStore<ApplicationUser> store)
            : base(store)
        {
        }
}
Run Code Online (Sandbox Code Playgroud)

同样在我的 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);                       
        }
    }
Run Code Online (Sandbox Code Playgroud)

请协助。

Yas*_*utt 5

我刚刚发现我已经Microsoft.AspNet.Identity.EntityFramework v1.0.0安装了但我需要v2.x. 我通过输入以下命令通过包管理器控制台安装它:

Install-Package Microsoft.AspNet.Identity.EntityFramework -Version 2.2.1
Run Code Online (Sandbox Code Playgroud)

在此更高版本中,UserStore实现IUserEmailStore了具有新电子邮件方法的功能。