Things to remember when using Membership.UpdateUser(MembershipUser user)

You got to love programming it thows you one curve ball efter another (c: thats why i love it so ,..
Her is a good thing to remember,.  when updating membership users, Lets say you want to do something like this

user.IsApproved = true;  //reactivate user
user.Comment = “mjau”; //change comment
Membership.UpdateUser(user);

this code will run just fine, but the result is not what you would expect
When it executes it will only update user.Comment = “mjau” on the other hand user.IsApproved will never be updated.
To make it work you must call Membership.UpdateUser() everytime you make an update, like this.

user.IsApproved = true;  //reactivate user
Membership.UpdateUser(user);

user.Comment = “mjau”; //change comment
Membership.UpdateUser(user);

Well,  that is my conclusion after some trail and error  runs

happy coding

Edit: Check out Sky Sanders Solution for this problem:  http://stackoverflow.com/questions/2721658/membership-updateuser-not-really-updating-the-database/2722173#2722173

Advertisements

5 Responses to Things to remember when using Membership.UpdateUser(MembershipUser user)

  1. Sky says:

    Trial and error is not a reliable technique and your information is misleading.

    You might get some insight by using reflector.

    • maanehunden says:

      Thanks for the comments. I’ve taken your input in to advise, but sometimes googling for answers doesn’t result in a solution , so the next best thing is trial and error, which is also meant as a mean to test the code.
      No I don’t provide all the code but only a snipped which made the difference in my code.

  2. Sky says:

    Your conclusion is incorrect. You have other issues that are not apparent in this post.

    See http://stackoverflow.com/questions/2721658/membership-updateuser-not-really-updating-the-database/2722173#2722173

    for more information

  3. Hi There,

    I don’t care if this blog posting is ‘wrong’, I worked for me. Thanks maanehunden!

    Bye for now
    Jason.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: