How to get number of users online in c#

Get number of users online in
.Net framework Membership.GetNumberOfUsersOnline() method allow us to get the number of users currently accessing an application. Membership class GetNumberOfUsersOnline() method exists in System.Web.Security namespace.

GetNumberOfUsersOnline() method return value data type is System.Int32. this integer returned value represents the number of users currently accessing an application.

this method returned the number of users online for the current ApplicationName where the last activity date is greater than the current time less the UserIsOnlineTimeWindow.

Membership.ApplicationName property allow us to get or set the application name. Membership.UserIsOnlineTimeWindow property specify the number of minutes after the last activity date/time stamp for a user during which the user is considered online.

the following c# example code demonstrate us how can we get the number of currently online users for an application programmatically.

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

<!DOCTYPE html>

<script runat="server">
    protected void Page_Load(object sender, System.EventArgs e) {
        Label1.Text = "Now OnLine users: " +

<html xmlns="">
<head runat="server">
    <title>Membership class example: how to get number of users online in</title>
    <form id="form1" runat="server">
        <h2>GetNumberOfUsersOnline method example</h2>
        <asp:LoginStatus ID="LoginStatus1" runat="server" />
        <br />
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="DarkGoldenrod"></asp:Label>
        <br /><br />
        <asp:LoginName ID="LoginName1" runat="server" FormatString="Hi {0}!" Font-Size="Large" ForeColor="Red" />


Related examples