Kenci
Kenci

Reputation: 4882

Why does membership IsApproved set itself to false?

I have some users where the IsApproved column in the database is set to false. This means that they cant login.

What could be the reason that this happens, and how can I prevent IsApproved to be set to false automatically?

Upvotes: 1

Views: 4514

Answers (3)

Mark Good
Mark Good

Reputation: 4303

Calling user.UnlockUser() sets IsApproved to false.

So, instead of this:

user.IsApproved = true;
user.UnlockUser(); // sets IsApproved to false
user.LastLoginDate = DateTime.Now;
Membership.UpdateUser(user);

Try this:

user.UnlockUser(); // sets IsApproved to false
user.IsApproved = true;  // resets IsApproved to true
user.LastLoginDate = DateTime.Now;
Membership.UpdateUser(user);

Upvotes: 0

Niranjan Singh
Niranjan Singh

Reputation: 18290

The MembershipUser.IsApproved Property details will clear you doubt regarding this.

Gets or sets whether the membership user can be authenticated. As like some administrator is moderating the website and it is false if your account has not yet been approved by the site's administrator. If he/she approves then it will set to true.

for more information, you should go through Examining ASP.NET's Membership, Roles, and Profile - Part 4 By Scott Mitchell

You can approve user by code as:

Dim User As MembershipUser
User = Nothing
User = Membership.GetUser("MyUsername")
If (User Not Nothing)
then 
User.IsApproved = False 
End If

Ref:
Make New User default to IsApproved = true
Error approving membership user
Unlocking and Approving User Accounts (C#)

  protected void IsApproved_CheckedChanged(object sender, EventArgs e)
    {
         // Toggle the user's approved status
         string userName = Request.QueryString["user"];
         MembershipUser usr = Membership.GetUser(userName);
         usr.IsApproved = IsApproved.Checked;
         Membership.UpdateUser(usr);
         StatusMessage.Text = "The user's approved status has been updated.";
    }

Use MemberShip to manage this stuff. Hope this help..

Upvotes: 2

Vijay EK
Vijay EK

Reputation: 184

The IsApproved column is set to false by default. There are different ways to change this default behaviour. See this link http://forums.asp.net/t/1086175.aspx/1 for changing.

Upvotes: 1

Related Questions