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

前端 未结 6 1810
名媛妹妹
名媛妹妹 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:07

    I am leaving this here for anyone that might have had a similar issue. I had exactly the same "symptoms". It turns out that the problem related to the password being stored not adhering to the configured password policy (at least one uppercase char, one lowercase char, etc etc).

    As per below comments and answers, in general, the same vague error message is thrown when any of the user creation constraints or policies are not followed.

    This might include the following:

    • Password policy not followed (this seems to be the most common cause)
    • Required fields being passed through as empty strings / null
    • Duplicate username or email

    There is really a wide range of issues which can cause this error to occur. If the above does not solve your problem, I suggest the following:

    1. Familiarize yourself with the rules and policies for identityprovider as it was set up for your solution
    2. As per @Ted's answer below, trace or put a breakpoint on the UserManager.Create method to view the result, as this will likely reveal the cause of your problem.

提交回复
热议问题