问题描述
我用RequireUniqueEmail=false
初始化UserManager
的UserValidator
,验证器肯定会接受重复的电子邮件(试图继承它并覆盖ValidateAsync()
方法).但是,当我尝试创建另一个具有唯一UserName
但具有Email
且已存在于AspNetUsers
表中的用户时,CreateAsync()
抛出
I initialize UserValidator
of the UserManager
with RequireUniqueEmail=false
, the validator accepts duplicate emails for sure (tried to inherit it and override the ValidateAsync()
method).However, when I try to create another user with a unique UserName
but with an Email
that already exists in the AspNetUsers
table, CreateAsync()
throws
只有一个验证错误:
我在CreateAsync
和RequireUniqueEmail=false
之前检查了UserValidator
的属性,因此已正确初始化.有趣的是,当我将RequireUniqueEmail
设置为true
时,它不会引发异常,只返回带有相同错误消息的IdentityResult
.
I've checked the properties of the UserValidator
before CreateAsync
and RequireUniqueEmail=false
, so it's initialized correctly.Funny thing is when I set RequireUniqueEmail
to true
it won't throw an exception, only return IdentityResult
with the same error message in it.
Owin v.3.1.0
(与v.3.0.1相同)
Owin v.3.1.0
is used (same with v.3.0.1)
推荐答案
经过长期深入的研究和调试,我发现您不仅在UserValidator
中具有RequireUniqueEmail
标志,而且在您的UserValidator
中也具有相同的标志IdentityDbContext<ApplicationUser>
,并且它们都应具有相同的值.
After a long and deep research and debugging I've found that you not only have RequireUniqueEmail
flag in your UserValidator
, but also same flag in your IdentityDbContext<ApplicationUser>
, and they both should have the same value.
这篇关于AspNet身份RequireUniqueEmail = false在CreateAsync上引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!