You need to get the updated user detail from last 15 minut. You can also set it to 30 min or greater than that.
HTML
<form id="form1" runat="server">
<div>
<table border="0" cellpadding="5" cellspacing="0">
<tr>
<td>
Number of login user
</td>
<td>
<asp:Label ID="lblUserCount" runat="server" />
</td>
</tr>
</table>
<hr />
Currently login user
<br />
<br />
<asp:GridView runat="server" ID="gvOnlineUsers" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
Width="200" />
</div>
</form>
Namespaces
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT UserId, UserName FROM Users WHERE DATEDIFF(mi,LastLoginDate,GETDATE()) <= 15", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
this.lblUserCount.Text = ds.Tables[0].Rows.Count.ToString();
this.gvOnlineUsers.DataSource = ds;
this.gvOnlineUsers.DataBind();
}
}
}
}
}
SQL
Simple User Login Form example in ASP.Net
Screenshot
