Delete all asp.net users with applicationId = xx

how do remove all asp.net users where application id = xx



frosty1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
Deleting all users and related data from a site using ASP.NET authentication is fairly simple. Useful if copying a database and you want to remove all the users, but keep the structure and other data (e.g. user content) intact.

Delete all users:
foreach (MembershipUser u in Membership.GetAllUsers())
{
 Membership.DeleteUser(u.UserName, true);
}
0
 
Carl TawnSystems and Integration DeveloperCommented:
There is no out-of-the-box way to do it, so you would need to write your own routine for doing it. Something like the following should work:
DECLARE @ApplicationName	NVARCHAR(256)
SET @ApplicationName = N'TestApplication'

DECLARE @ApplicationID	UNIQUEIDENTIFIER;
SELECT @ApplicationID = [ApplicationId] FROM [aspnet_Applications] WHERE [ApplicationName] = @ApplicationName;

DECLARE UserCursor CURSOR
	FOR SELECT [UserName] FROM [aspnet_Users] WHERE [ApplicationId] = @ApplicationID;

DECLARE @UserName NVARCHAR(256);
DECLARE @TableCount INT;

OPEN UserCursor;
FETCH NEXT FROM UserCursor INTO @UserName
WHILE (@@FETCH_STATUS = 0)
BEGIN

	EXEC [aspnet_Users_DeleteUser] @ApplicationName, @UserName, 8, @TableCount OUTPUT;

	FETCH NEXT FROM UserCursor INTO @UserName
END

CLOSE UserCursor;
DEALLOCATE UserCursor; 

Open in new window

0
 
frosty1Author Commented:
thanks guys, actually both answered would do the trick. I selected that later as i'm comfortable in C# that SQL.
0
All Courses

From novice to tech pro — start learning today.