How do I disable an account with the ASP.NET Membership Provider?
14,352
Solution 1
MembershipUser user = Membership.GetUser("Yourusername");
if(user!=null){
user.IsApproved=false;
Membership.UpdateUser(user);
}
Solution 2
There isn't an exposed method to do so, but you can always code a sproc and a helper method to do that for you.
Alternately, code a loop to lock them out with programmatic code ;)
for (i=0;i<lockoutTries;i++) membership.login(username,badpassword_constant);
Related videos on Youtube
Author by
Mindtree
Updated on January 09, 2020Comments
-
Mindtree over 4 years
I'm using asp.net membership provider. and I need to block user account in case if the user post spam. How can I accomplish it using build in features of the Membership Provider.
Can I use IsLockedOut? If so how can i update it programmatically?
Thank you
-
gbs over 13 yearsno you cannot use isLockedOut, it is readonly. But you can use IsApproved as shown below in my answer.
-
-
jcolebrand over 13 yearsThat "unapproves" them. What are the ramifications of doing so?
-
gbs over 13 yearsIf IsApproved user is false, user will not be authenticated. It is same as IsLockedOut but IsLockedOut is set automatically depending on invalid outputs. IsApproved is the only property that can be of use in this scenario.
-
Mindtree over 13 yearsThank you I think it will work for me. Because its the best solution so far
-
jcolebrand over 13 years@Marc_s ~ It is a HORRID hack but it is easily programmed, even by someone who can't write code. The earlier method I suggest and the logic it involves is much saner. However it requires a little more work to maintain.