Asp.net mvc 将标识1更新为2后没有注册IUserTokenProvider错误
我已将项目中的标识更新为版本2,并在Asp.net mvc 将标识1更新为2后没有注册IUserTokenProvider错误,asp.net-mvc,asp.net-identity,Asp.net Mvc,Asp.net Identity,我已将项目中的标识更新为版本2,并在AccountController中的ForgotPassword操作中收到未注册IUserTokenProvider错误: string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); 然后,我基于和在IdentityConfig中实现IUserTokenProvider接口,我使用: public static ApplicationUserManager Crea
AccountController
中的ForgotPassword
操作中收到未注册IUserTokenProvider错误
:
string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
然后,我基于和在IdentityConfig
中实现IUserTokenProvider
接口,我使用:
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
//other code
manager.UserTokenProvider = new MyUserTokenProvider<ApplicationUser>();
return manager;
}
我不知道问题出在哪里。我找到了解决办法。每件事都是在identityconfig中真正实现的。问题出在
AccountController
中。我创建了一个新的UserManager
对象,没有使用UserManager
的注入对象:
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
_userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
}
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
}
public UserManager<ApplicationUser> UserManager { get; private set; }
publiccountcontroller()
:此(新的UserManager(新的UserStore(新的ApplicationDbContext()))
{
_userManager=newusermanager(newuserstore(newapplicationdbcontext());
}
公共帐户控制器(用户管理器用户管理器)
{
UserManager=UserManager;
}
公共用户管理器用户管理器{get;private set;}
在新版本中:
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager)
{
UserManager = userManager;
}
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
publiccountcontroller()
{
}
公共帐户控制器(ApplicationUserManager用户管理器)
{
UserManager=UserManager;
}
公共应用程序管理员用户管理器
{
得到
{
返回_userManager??HttpContext.GetOwinContext().GetUserManager();
}
专用设备
{
_userManager=value;
}
}
这项工作现在很好。MyUserTokenProvider看起来怎么样?
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager)
{
UserManager = userManager;
}
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}