我有一个自定义成员资格提供程序,其中包含create user method:
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
if ((RequiresUniqueEmail == true) && !string.IsNullOrEmpty(GetUserNameByEmail(email)))
{
status = MembershipCreateStatus.DuplicateEmail;
return null;
}
MembershipUser userMember = GetUser(username, true);
if (userMember == null)
{
User user = new User();
user.Name = username;
user.Salt = user.GenerateSalt();
user.Password = user.hashedpassword(password);
user.Email = email;
user.isApproved = isApproved;
user.Register();
status = MembershipCreateStatus.Success;
}
else
{
status = MembershipCreateStatus.DuplicateUserName;
}
return null;
}
但是当我尝试使用这种方法时:
try
{
Membership.CreateUser(Name, Password, Mail);
}
catch (Exception ex)
{
Defaults.Error = ex;
}
我得到例外{"没有错误。"}。 但是创建了新用户,登录和注销没有问题。
答案 0 :(得分:0)
抱歉!愚蠢的错误......
return GetUser(username, true);
应该在最后而不是
return null;