1

I am writing an asp.net membership provider using Entity code first and I need some help understanding how to Update the MembershipUser object.

The UpdateUsert(MembershipUser user) override method needs to be implemented and consists of a MembershipUser parameter.

The following code does not work and I am not sure how to tie the MembershipDBContext with the supplied membership user so that the user is updated. Thanks for the help.

public override void UpdateUser(MembershipUser user)
{
    MembershipDBModel userToUpdate = _getMembershipDBModelUser(user.UserName);

    userToUpdate.IsLockedOut = user.IsLockedOut;


    using (MembershipDBContext db = new MembershipDBContext())
    {
        db.SaveChanges();
    }
}
Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
ChiliYago
  • 11,341
  • 23
  • 79
  • 126

1 Answers1

1

Why not use the built in functionality for the MembershipProvider?

MembershipUser user = Membership.GetUser();
user.IsApproved = false;
Membership.UpdateUser(user);
Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
  • Because I am creating a custom membership provider and need to implement the update UpdateUser(user) method. – ChiliYago May 13 '11 at 17:05
  • Even so, you should follow the base functionality. http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider – Dustin Laine May 13 '11 at 17:08
  • I am writing my OWN save methods. Calling Membership.UpdateUser() does nothing because no code exists. I am overriding that method. – ChiliYago May 13 '11 at 18:48
  • 1
    Also the user.IsLockedOut property is read only in this context which is also problematic. My approach was to get the record from my db update it and return it. Maybe I am missing a concept or something but i am not following you. – ChiliYago May 13 '11 at 18:51
  • @ChiliYago, good point. The lockout should be used for password failures, and the IsApproved field for this scenario. – Dustin Laine May 13 '11 at 18:53