How to get all users in c#

Get membership all users name in
.Net framework Membership.GetAllUsers() method allow us to get a collection of all the users in the database. Membership class GetAllUsers() method exists in System.Web.Security namespace.

GetAllUesrs() method return value type is System.Web.Security.MembershipUserCollection. this return value is a MembershipUserCollection of MembershipUser objects representing all of the users in the database.

In the bellow example code, we get the collection of all membership users and data bind this collection with a ListBox server control. if the collection is large then this method degrade the performance of application.

Membership.GetAllUsers(Int32, Int32, Int32) overloaded method allow us to get a collection of all the users in the database in pages of data. this overloaded method provide paging support of membership users list.

The following c# example code demonstrate us how can we get all the membership users in database programmatically at run time in an application.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        ListBox1.DataSource = Membership.GetAllUsers();

<html xmlns="">
<head runat="server">
    <title>GetAllUsers method example: how to get user list in</title>
    <form id="form1" runat="server">
        <h2>GetAllUsers Method Example</h2>
        <asp:Label ID="Label1" runat="server" Text="All Users" AssociatedControlID="ListBox1"></asp:Label>
        <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get All Users" OnClick="Button1_Click" />
Related example