开发者

How do you update the aspnetdb membership IsApproved value?

开发者 https://www.devze.com 2023-01-04 03:34 出处:网络
I need to update existing users IsApproved status in the aspnet_Membership table. I have the code below tha开发者_StackOverflow中文版t does not seem to be working. The user.IsApproved property is upda

I need to update existing users IsApproved status in the aspnet_Membership table. I have the code below tha开发者_StackOverflow中文版t 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;          
    }


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 );
   }      
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消