没有IUserTokenProvider注册 [英] No IUserTokenProvider is registered

查看:896
本文介绍了没有IUserTokenProvider注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新 Asp.Net身份睿我的申请表的1.0〜2.0。

I recently updated Asp.Net Identity Core of my application form 1.0 to 2.0.

有,我想尝试像 GenerateEmailConfirmationToken ,新功能等。

There are new features which I wanted to try like GenerateEmailConfirmationToken, etc.

我用<一个href=\"https://aspnet.$c$cplex.com/SourceControl/latest#Samples/Identity/Identity-PasswordPolicy/Identity-PasswordPolicy/Controllers/AccountController.cs\">this项目作为参考。

当用户尝试注册,我注册的邮政法的执行过程中出现错误

When the user tries to register, I get error during the execution of Post method of Register

private readonly UserManager<ApplicationUser> _userManager;     

public ActionResult Register(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {
        var ifUserEXists = _userManager.FindByName(model.EmailId);
        if (ifUserEXists == null) return View(model);
        var confirmationToken = _userRepository.CreateConfirmationToken();//this is how i'm generating token currently.                
        var result = _userRepository.CreateUser(model,confirmationToken);
        var user = _userManager.FindByName(model.EmailId);
        if (result)
        {
            var code = _userManager.GenerateEmailConfirmationToken(user.Id);//error here
            _userRepository.SendEmailConfirmation(model.EmailId, model.FirstName, confirmationToken);
            //Information("An email is sent to your email address. Please follow the link to activate your account.");
            return View("~/Views/Account/Thank_You_For_Registering.cshtml");
        }     
    }

    //Error("Sorry! email address already exists. Please try again with different email id.");
    ModelState.AddModelError(string.Empty, Resource.AccountController_Register_Sorry__User_already_exists__please_try_again_);
    return View(model);
}

在该行

 var code = _userManager.GenerateEmailConfirmationToken(user.Id);

我得到的错误说:

I get error saying:

No IUserTokenProvider is registered.

现在,我只是想看到什么样的$ C $的c那么它产生。
有一些变化,我需要对我的 ApplicationUser 类,从 IdentityUser 类继承?

或者是有什么我需要改变,以获得这些功能的工作?

Or is there something I need to change to get those function work?

推荐答案

您必须指定一个 UserTokenProvider 来生成令牌。

You have to specify a UserTokenProvider to generate a token.

using Microsoft.Owin.Security.DataProtection;
using Microsoft.AspNet.Identity.Owin;
// ...

var provider = new DpapiDataProtectionProvider("Sample");

var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>());

userManager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(
    provider.Create("EmailConfirmation"));

您也应该看看这篇文章:<一href=\"http://blogs.msdn.com/b/webdev/archive/2014/02/18/adding-two-factor-authentication-to-an-application-using-asp-net-identity.aspx\">Adding双因素身份验证使用ASP.NET身份应用程序。

You should also read this article: Adding Two Factor Authentication to an Application Using ASP.NET Identity.

这篇关于没有IUserTokenProvider注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆