In this post I will explain how to get the list of online users in asp.net.
<asp:GridView ID="gvOnlineUserList" runat="server" Font-Bold="True" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:CheckBoxField DataField="IsOnline" HeaderText="Is Online" />
<asp:BoundField DataField="IsApproved" HeaderText="Is Approved" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="CreationDate" HeaderText="Creation Date" />
<asp:BoundField DataField="LastActivityDate" HeaderText="Last Activity Time" />
<asp:BoundField DataField="LastLockoutDate" HeaderText="Last Lockout Date" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<EmptyDataTemplate>
No User Online
</EmptyDataTemplate>
</asp:GridView>
<Columns>
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:CheckBoxField DataField="IsOnline" HeaderText="Is Online" />
<asp:BoundField DataField="IsApproved" HeaderText="Is Approved" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="CreationDate" HeaderText="Creation Date" />
<asp:BoundField DataField="LastActivityDate" HeaderText="Last Activity Time" />
<asp:BoundField DataField="LastLockoutDate" HeaderText="Last Lockout Date" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<EmptyDataTemplate>
No User Online
</EmptyDataTemplate>
</asp:GridView>
OnlineUserList.aspx.cs
public MembershipUserCollection OnlineUsers = new MembershipUserCollection();
public MembershipUserCollection AllUsers = new MembershipUserCollection();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.BindOnlineUsers();
}
}
private void BindOnlineUsers()
{
AllUsers = Membership.GetAllUsers();
foreach (MembershipUser user in AllUsers)
{
if (user.IsOnline)
{
OnlineUsers.Add(user);
}
}
gvOnlineUserList.DataSource = OnlineUsers;
gvOnlineUserList.DataBind();
}
public MembershipUserCollection AllUsers = new MembershipUserCollection();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.BindOnlineUsers();
}
}
private void BindOnlineUsers()
{
AllUsers = Membership.GetAllUsers();
foreach (MembershipUser user in AllUsers)
{
if (user.IsOnline)
{
OnlineUsers.Add(user);
}
}
gvOnlineUserList.DataSource = OnlineUsers;
gvOnlineUserList.DataBind();
}
No comments:
Post a Comment