AspNet Identity RequireUniqueEmail = false throws exception on CreateAsync

拟墨画扇 提交于 2020-02-06 07:54:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!