且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MVC5:UserManager.AddToRole():“将用户添加到角色时出错:未找到UserId"?

更新时间:2023-02-25 21:02:28

我在这里留给可能有类似问题的任何人使用.我有完全相同的症状".事实证明,与存储密码有关的问题未遵循所配置的密码策略(至少一个大写字符,一个小写字符等).

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.

这可能包括以下内容:

  • 未遵循密码政策(这似乎是最常见的原因)
  • 必填字段以空字符串/null的形式传递
  • 用户名或电子邮件重复

确实存在很多可能导致此错误发生的问题.如果以上方法不能解决您的问题,建议您执行以下操作:

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. 熟悉为身份解决方案设置的身份提供商的规则和政策
  2. 按照下面@Ted的回答,在UserManager.Create方法上跟踪或放置一个断点以查看结果,因为这很可能揭示问题的原因.