Extend Membership API, MembershipUser

2019-04-01 13:36发布

问题:

I created my own database schema to store user information.

CREATE TABLE [dbo].[MyCustomMembership_Users](
[UserId] [uniqueidentifier] NOT NULL,
[UserName] [nvarchar](256) NOT NULL,
[LoweredUserName] [nvarchar](256) NOT NULL,
[MobileAlias] [nvarchar](16) NULL,
[IsAnonymous] [bit] NOT NULL,
[LastActivityDate] [datetime] NOT NULL,
[FirstName] [nvarchar](256) NULL,
[MiddleName] [nvarchar](256) NULL,
[LastName] [nvarchar](256) NULL)

Then I extend the MembershipProvider and MembershipUser and create the overriden methods. How can I pass the additional information when I call the CreateUser Method? I am aware I can use profile for this but I also want to be able to do it this way and if it comes out to be too complicated that I will go the profile route.

public class MyMembershipProvider : MembershipProvider
{
  public override MembershipUser CreateUser(string username, string password, 
string email, string passwordQuestion, string passwordAnswer, bool isApproved, 
object providerUserKey, out MembershipCreateStatus status)
    {
        throw new NotImplementedException();
    }
}
public class MyMembershipUser : MembershipUser
{
    private string _firstName;
    public string FirstName { get { return _firstName; } set { _firstName = value; } }

    private string _middleName;
    public string MiddleName { get { return _middleName; } set { _middleName = value; } }

    private string _lastName;
    public string LastName { get { return _lastName; } set { _lastName = value; } }

    public MyMembershipUser() : base()
    {
        this.FirstName = _firstName;
        this.MiddleName = _middleName;
        this.LastName = _lastName;
    }
}

回答1:

You could pass a MyMembershipUser in the providerUserKey object