asp.net - 为什么Membership.CreateUser失败?

标签 asp.net asp.net-membership

对于这个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/

相关文章:

c# - 导出到 .csv 文件

c# - 如何从 ASP.NET 中的表单访问字段数组?

asp.net-mvc - 使用 ASP.Net Membership,获取所有用户

mysql - MySQL 的 ASP.NET MVC 3 成员资格

asp.net - 在 ASP.NET MembershipProvider 中获取当前 ApplicationId

javascript - 使用javascript无法正确加载标签背景图片

asp.net - 在 ASP.NET 2.0 WebForms 中使用 UrlRewrite 时如何优雅地处理 ReturnUrl

c# - 使用构建管理器类加载 ASPX 文件并填充其控件

.net - ASP.NET MVC3 中基于权限的授权

asp.net - 在 ASP.NET 成员提供者数据库中加密密码