Reputation: 8415
I'm trying to give website admin ability to activate /deactivate or unlock multiple users by selecting users and clicking a button .
asp.net membership doesn't have such method ( as far as I know ) . I don't want to call UpdateUser() one time for each user .
any idea ?
Upvotes: 0
Views: 1191
Reputation: 5987
You could use the following logic, however better you use the able way but the logic inside the stored procedure mentioned above is following.
UPDATE dbo.aspnet_Membership
SET IsLockedOut = 0,
FailedPasswordAttemptCount = 0,
FailedPasswordAttemptWindowStart = CONVERT(datetime, '17540101', 112),
FailedPasswordAnswerAttemptCount = 0,
FailedPasswordAnswerAttemptWindowStart = CONVERT(datetime, '17540101', 112),
LastLockoutDate = CONVERT(datetime, '17540101', 112 )
WHERE @UserId IN (YOUR COLLECTED USERID"S WITH COMMA)
Now you need to build logic that call the above SP logic and by this you can get things done.
Upvotes: 1
Reputation: 9296
In that case you will have to create a custom stored procedure to which you send a list of user names in a comma separated format and process them on the server. This will be slightly complex and ugly work because you will have to send Application name as well. For each user that your procedure processes call aspnet_Membership_UnlockUser
SP passing it apllication name (@ApplicationName) and user name (@UserName).
Have a look at the logic of aspnet_Membership_UnlockUser
SP. Probably you can come up with a better solution.
EDIT: Another solution would be to create a type through .NET assembly that works like a table with a list of usernames that you pass as UDF parameter to SqlCommand. On the server you would use this parameter to either join it with Jigar's query or loop for each item in your type. That could be a better solution because you would be able to reuse the assembly for other such scenarios.
Upvotes: 1