Quantcast
Channel: TexoTela - Weaving a Web » CSharp
Viewing all articles
Browse latest Browse all 4

ASP.NET Snippet: Delete All Users and Roles

$
0
0

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);
}

Delete all roles:

foreach (string role in Roles.GetAllRoles())
{
 Roles.DeleteRole(role);
}

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images