对于这个overload:
如果 CreateUser("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4a4c5a4d515e525a7f5a525e5653115c5052" rel="noreferrer noopener nofollow">[email protected]</a>","pwd")
失败,并显示错误消息:提供的电子邮件地址无效。请检查该值并重试。
但是CreateUser("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="83f6f0e6f1ede2eee6c3e6eee2eaefade0ecee" rel="noreferrer noopener nofollow">[email protected]</a>","pwd","<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="05707660776b646860456068646c692b666a68" rel="noreferrer noopener nofollow">[email protected]</a>")
,成功了!
为什么?
最佳答案
考虑这样的方法可能会更好:
CreateUser(Username, Password);
CreateUser(Username, Password, Email);
如果没有反射(reflect)代码,我不能肯定地说 100%,但我敢打赌这些函数只是调用一个接受每个可能参数的内部函数。
所以你的第一个调用(简化的)实际上是:
CreateUser("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a6a0b6a1bdb2beb693b6beb2babffdb0bcbe" rel="noreferrer noopener nofollow">[email protected]</a>", "pwd", null);
如果您已将提供商配置为需要电子邮件地址,那么显然 null
无效。
来自MSDN docs :
The SqlMembershipProvider provides an option to require a unique e-mail address for each user. If the RequiresUniqueEmail property is true, you will need to use one of the CreateUser overloads that allows you to specify an e-mail address for the user being created. Otherwise, a MembershipCreateUserException will be thrown.
关于asp.net - 为什么Membership.CreateUser失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10560414/