问题
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
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
There is just one validation error:
Email myemail@email.com is already taken.
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
is used (same with v.3.0.1)
回答1:
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.
来源:https://stackoverflow.com/questions/46478593/aspnet-identity-requireuniqueemail-false-throws-exception-on-createasync