How do you update the aspnetdb membership IsApproved value?
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
精彩评论