我正在为测试目的创建用户,使用:
string username = ...
string password = ...
string email = "******** not a valid email address! *********";
MembershipUser NewUser = Membership.CreateUser(userName, password, email, "no question", "no answer", true, out createStatus);
if (NewUser == null)
{
switch (createStatus)
{
case MembershipCreateStatus.DuplicateUserName:
throw new Exception("There already exists a user with this username.");
case MembershipCreateStatus.InvalidEmail:
throw new Exception("There email address you provided in invalid.");
case MembershipCreateStatus.InvalidPassword:
throw new Exception("The password you provided is invalid. It must be seven characters long.");
default:
throw new Exception("There was an unknown error; the user account was NOT created.");
}
}
执行此操作时,将创建一个新用户,它不会因 NewUser==null, MembershipCreateStatus.InvalidEmail而失败,这是我所期望的。
知道为什么吗?
这是 config 中的成员资格部分(如果有影响的话),尽管我不知道如何:
<membership defaultProvider="myProvider">
<providers>
<add
name="myProvider"
applicationName="/"
connectionStringName="myconnectionsString"
enablePasswordRetrieval="true"
enablePasswordReset="true"
passwordFormat="Clear"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
minRequiredNonalphanumericCharacters="0"
type="System.Web.Security.SqlMembershipProvider"
/>
</providers>
</membership>
提前致谢!