1

我有一个具有创建用户方法的自定义成员资格提供程序:

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;
    }

我得到一个异常 {"No Error."}。但是,新用户已创建,登录和注销没有问题。

4

1 回答 1

0

对不起!愚蠢的错误..

return GetUser(username, true);

应该在最后而不是

return null;
于 2013-09-21T00:54:55.317 回答