List of online users using membership asp.net

老子叫甜甜 提交于 2019-12-10 10:54:55

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/14214624/list-of-online-users-using-membership-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!