MVC5: UserManager.AddToRole(): “Error Adding User to Role: UserId not found”?

前端 未结 6 1817
名媛妹妹
名媛妹妹 2020-12-25 13:33

I have been experimenting with MVC5/EF6 and trying out the new Identity Authentication with Code-First Migrations. Everything in the solution is currently building and I can

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-25 14:01

    This saved my 2nd day . Thanks @Daffy Punk. In my case the issue was password. which was "abc" before.

    var studentPassword = "abcABC_9";
                            var user = new ApplicationUser { UserName = "abc", Email = 1@gmail.com };
                            var UserManager = new UserManager(new UserStore(context));
                            var result = await UserManager.CreateAsync(user, studentPassword.ToString());
                            await UserManager.AddToRoleAsync(user.Id, "Student");
    

提交回复
热议问题