views:

25

answers:

2

I need to update existing users IsApproved status in the aspnet_Membership table. I have the code below that does not seem to be working. The user.IsApproved property is updated but it is not saving it to the database table. Are there any additional calls I need to make?
Any suggestions? Thanks.

    /// <summary>
    /// Updates a users approval status to the specified value
    /// </summary>
    /// <param name="userName">The user to update</param>
    /// <param name="isApproved">The updated approval status</param>       
    public static void UpdateApprovalStatus(string userName, bool isApproved)
    {
       MembershipUser user = Membership.GetUser(userName);

       if (user != null)
           user.IsApproved = isApproved;          
    }
+3  A: 

You need to call UpdateUser after you make the change.

/// <summary>
/// Updates a users approval status to the specified value
/// </summary>
/// <param name="userName">The user to update</param>
/// <param name="isApproved">The updated approval status</param>       
public static void UpdateApprovalStatus(string userName, bool isApproved)
{
   MembershipUser user = Membership.GetUser(userName);

   if (user != null)
   {
       user.IsApproved = isApproved;
       Membership.UpdateUser( user );
   }      
}
tvanfosson
A: 

You should use Membership.UpdateUser(); at the end of your code here more from MSDN http://msdn.microsoft.com/en-us/library/system.web.security.membership.updateuser.aspx

GIbboK