I have some really old (ugly) code from an app I built a few years back. It's pretty much a hack up of a gridview control which uses the aspnet_Membership_UnlockUser stored proc as the delete command with the key set as the username of the locked out user in the gridrow. I didn't even use C#. Here's what I have:
<asp:Label runat="server" ID="LblLockedUsers" Text="Locked Out Users:" />
<asp:SqlDataSource ID="SqlLockedUsers" runat="server" ConnectionString='<%$ ConnectionStrings:myConnString %>'
SelectCommand="selLockedOutUsers" SelectCommandType="StoredProcedure" DeleteCommand="aspnet_Membership_UnlockUser"
DeleteCommandType="StoredProcedure" />
<asp:GridView ID="GvLockedUsers" runat="server" AllowPaging="True" PageSize="5" AutoGenerateColumns="False"
DataKeyNames="UserName" DataSourceID="SqlLockedUsers" AllowSorting="True" GridLines="None"
Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LnkUnlock" CommandArgument='<%# Eval("UserName") %>' CommandName="Delete" runat="server">Unlock</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="User Name" ReadOnly="True" SortExpression="UserName" />
<asp:CheckBoxField DataField="IsLockedOut" HeaderText="Locked Out" ReadOnly="True" SortExpression="IsLockedOut" />
<asp:BoundField DataField="LastLockoutDate" HeaderText="Last Lockout" SortExpression="LastLockoutDate" ReadOnly="True" />
<asp:BoundField DataField="failedPasswordAttemptCount" HeaderText="Failed Password Attempts" SortExpression="failedPasswordAttemptCount" ReadOnly="True" />
</Columns>
<EmptyDataTemplate>
No users are locked out at this time.
</EmptyDataTemplate>
</asp:GridView>
Here's the old stored proc I wrote which is used by the gridview. This all can be done so much better, but this is what I did back then and it works well.
CREATE PROCEDURE [dbo].[selLockedOutUsers]
AS
SELECT
m.ApplicationId as applicationId,
a.ApplicationName as applicationName,
m.UserId as userId,
u.UserName as UserName,
m.IsLockedOut as isLockedOut,
m.LastLoginDate as lastLoginDate,
m.LastLockoutDate as lastLockoutDate,
m.FailedPasswordAttemptCount as failedPasswordAttemptCount
FROM
aspnet_Membership m
JOIN aspnet_Users u ON m.UserId = u.UserId
JOIN aspnet_Applications a ON m.ApplicationId = a.ApplicationId
WHERE
m.IsLockedOut = '1'
Here's my modified aspnet_Membership_UnlockUser stored proc. As you can see, I removed the app name parameter and just set it in the proc manually. That way I only need to pass the username as a parameter.
ALTER PROCEDURE [dbo].[aspnet_Membership_UnlockUser]
--@ApplicationName nvarchar(256), --replaced with '/'
@UserName nvarchar(256)
AS
BEGIN
DECLARE @UserId uniqueidentifier
SELECT @UserId = NULL
SELECT @UserId = u.UserId
FROM dbo.aspnet_Users u, dbo.aspnet_Applications a, dbo.aspnet_Membership m
WHERE LoweredUserName = LOWER(@UserName) AND
u.ApplicationId = a.ApplicationId AND
LOWER('/') = a.LoweredApplicationName AND
u.UserId = m.UserId
IF ( @UserId IS NULL )
RETURN 1
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 = UserId
RETURN 0
END