简体   繁体   中英

List of online users using membership asp.net

I want to have a list that contains online users in my web site i use this code in local host but it did't shows me any user. Can any body help me? where did i make mistake?

  MembershipUserCollection users;


        if (!IsPostBack)
        {
            // Bind users to ListBox.
            List<MembershipUser> onlineUsers = new List<MembershipUser>();
            foreach (MembershipUser user in Membership.GetAllUsers())
            {

                if (user.IsOnline)
                {
                    onlineUsers.Add(user);

                }

            }
            ListBox1.DataSource = users;
            ListBox1.DataBind();

Try changing this line:

ListBox1.DataSource = users;

To this:

ListBox1.DataSource = onlineUsers;

Also do not forget to set the DataKeyField and DataValueField properties on the ListBox1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM