最佳答案
我最近更新了我的申请表1.0到2.0的 Asp.Net Identity Core。
有一些新的功能,我想尝试像 GenerateEmailConfirmationToken等。
我使用 这个项目作为参考。
当用户尝试注册时,在执行 Post 方法 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);
如果我说:
No IUserTokenProvider is registered.
现在,我只想看看它会生成什么样的代码。
是否需要对从 IdentityUser类继承的 ApplicationUser类做一些更改?
或者我需要改变什么才能让这些功能正常工作?