AspNet Identity RequireUniqueEmail = false 在 CreateAsync 上抛出异常
AspNet Identity RequireUniqueEmail = false throws exception on CreateAsync
我用 RequireUniqueEmail=false
初始化 UserManager
的 UserValidator
,验证器肯定会接受重复的电子邮件(试图继承它并覆盖 ValidateAsync()
方法)。
但是,当我尝试创建另一个具有唯一 UserName
但 Email
已经存在于 AspNetUsers
table 中的用户时,CreateAsync()
throws
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
只有一个验证错误:
Email myemail@email.com is already taken.
我在 CreateAsync
和 RequireUniqueEmail=false
之前检查了 UserValidator
的属性,因此它已正确初始化。
有趣的是,当我将 RequireUniqueEmail
设置为 true
时,它不会抛出异常,只有 return IdentityResult
具有相同的错误消息。
使用Owin v.3.1.0
(与v.3.0.1相同)
经过长期深入的研究和调试,我发现您不仅在 UserValidator
中有 RequireUniqueEmail
标志,而且在 IdentityDbContext<ApplicationUser>
中也有相同的标志,并且它们两者应该具有相同的值。
我用 RequireUniqueEmail=false
初始化 UserManager
的 UserValidator
,验证器肯定会接受重复的电子邮件(试图继承它并覆盖 ValidateAsync()
方法)。
但是,当我尝试创建另一个具有唯一 UserName
但 Email
已经存在于 AspNetUsers
table 中的用户时,CreateAsync()
throws
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
只有一个验证错误:
Email myemail@email.com is already taken.
我在 CreateAsync
和 RequireUniqueEmail=false
之前检查了 UserValidator
的属性,因此它已正确初始化。
有趣的是,当我将 RequireUniqueEmail
设置为 true
时,它不会抛出异常,只有 return IdentityResult
具有相同的错误消息。
Owin v.3.1.0
(与v.3.0.1相同)
经过长期深入的研究和调试,我发现您不仅在 UserValidator
中有 RequireUniqueEmail
标志,而且在 IdentityDbContext<ApplicationUser>
中也有相同的标志,并且它们两者应该具有相同的值。