3
Hello Sushant,
You can achieve this using global.ascx file,
// Global.asax.cs
using System;
using System.Web;
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Initialize active users count
Application["ActiveUsers"] = 0;
}
void Session_Start(object sender, EventArgs e)
{
// Increment active users count
Application.Lock();
Application["ActiveUsers"] = (int)Application["ActiveUsers"] + 1;
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// Decrement active users count
Application.Lock();
Application["ActiveUsers"] = (int)Application["ActiveUsers"] - 1;
Application.UnLock();
}
}
If you wish to display count on your webpage then you can display the active users count in a webpage:
// Inside your .aspx.cs file
protected void Page_Load(object sender, EventArgs e)
{
int activeUsers = (int)Application["ActiveUsers"];
// Display active users count on the webpage
lblActiveUsers.Text = "Active Users: " + activeUsers.ToString();
}

2
To determine the count of agents currently logged in, you can utilize SQL queries in Oracle. By querying the log table for active sessions (where logout time is null or within a specific range), you can calculate the number of agents logged in. Here's a sample query to achieve this:
SELECT COUNT(*) AS LoggedInAgents
FROM log_table
WHERE logout_time IS NULL; -- Assuming NULL logout_time indicates an active session
This query counts the number of agents with no logout time recorded, indicating they are currently logged in. You can then display this count in your portal interface.
2
Hello Sushant,
You can create one method using which you can get active use count,
As per my understanding once the user logs in you will make an entry in the table, so using below sql query you can find logs in user count,
SELECT COUNT(UserId) AS active_users_count FROM log_table WHERE logout_time IS NULL
private string connectionString = "your_connection_string_here";
public int GetActiveUsersCount()
{
int activeUsersCount = 0;
string query = "SELECT COUNT(UserId) AS active_users_count FROM log_table WHERE logout_time IS NULL";
using (OracleConnection connection = new OracleConnection(connectionString))
{
using (OracleCommand command = new OracleCommand(query, connection))
{
try
{
connection.Open();
activeUsersCount = Convert.ToInt32(command.ExecuteScalar());
}
catch (Exception ex)
{
// Handle exceptions
Console.WriteLine("Error: " + ex.Message);
}
}
}
return activeUsersCount;
}
1
Thank you all for reply.
I was thinking about below code, but i think it will take more time to load as there are many users.
Any fast way to achieve, maybe from global.asax file or ApplicationSession?