将用户分配给角色错误

时间:2018-04-02 08:26:39

标签: c# asp.net asp.net-mvc asp.net-mvc-5

我有一个注册过程,人们提供电子邮件/密码.. 他们也将提供会员资格(或角色)

我的AccountController注册方法看起来像..

var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
            var result = await UserManager.CreateAsync(user, model.Password);
            await this.UserManager.AddToRoleAsync(user.Id, model.SelectedMembershipType);
            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");
            }
            AddErrors(result);

但我得到一个错误说明.. enter image description here

基本上表示未找到UserId。有没有人之前有这个,你能推荐一个解决方案来解决它吗?提前谢谢。

0 个答案:

没有答案