gpt4 book ai didi

asp.net - 如何使用 mvc 中的自定义成员身份添加更多自定义字段?

转载 作者:行者123 更新时间:2023-12-02 12:15:49 26 4
gpt4 key购买 nike

我已经重写了成员资格方法来创建自定义成员资格。

在帐户模型中,我重写了方法CreateUser:

public override MembershipUser CreateUser(string username, string password,
string email, string passwordQuestion, string passwordAnswer,
bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(
username, password, true);
OnValidatingPassword(args);

if (args.Cancel)
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}

if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
{
status = MembershipCreateStatus.DuplicateEmail;
return null;
}

MembershipUser u = GetUser(username, false);
if (u == null)
{
UserRepository _user = new UserRepository();

// Here I call my new method which has fields I've created in the
// User table; I'm using entity framework.
_user.CreateUser(username, password, email);
status = MembershipCreateStatus.Success;
return GetUser(username, false);
}
else
{
status = MembershipCreateStatus.DuplicateUserName;
}

return null;
}

public MembershipUser CreateUser(string username, string password,
string email)
{
using (CustomMembershipDB db = new CustomMembershipDB())
{
User user = new User();
user.UserName = username;
user.Email = email;
user.PasswordSalt = CreateSalt();
user.Password = CreatePasswordHash(password, user.PasswordSalt);
user.CreatedDate = DateTime.Now;
user.IsActivated = false;
user.IsLockedOut = false;
user.LastLockedOutDate = DateTime.Now;
user.LastLoginDate = DateTime.Now;

//Generate an email key
// user.NewEmailKey = GenerateKey();

db.AddToUsers(user);
db.SaveChanges();

//send mail
// SendMail(user);

return GetUser(username);
}
}

现在我需要添加两个字段,例如名字和姓氏,但是如何将其传递给上面的方法?

由于覆盖方法 CreateUser 如果我向其中添加名字和姓氏等参数,则会出现错误:(

最佳答案

您需要实现自定义成员(member)用户。这是一个示例实现:

另请看一下此线程:

关于asp.net - 如何使用 mvc 中的自定义成员身份添加更多自定义字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8760223/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com