本文介绍了AspNet身份RequireUniqueEmail = false在CreateAsync上引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我用RequireUniqueEmail=false初始化UserManagerUserValidator,验证器肯定会接受重复的电子邮件(试图继承它并覆盖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

只有一个验证错误:

我在CreateAsyncRequireUniqueEmail=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上引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 00:04