Count Number of Online user in Asp.net Application.

Count Number of Online user in Asp.net Application.

For getting count of User in your application, you need to add Global.aspx File in your project.
After adding Global file just follow these simple 4 steps.

Step 1:- Application setting code in Global.asax

Global.asax

<%@ Application Language="C#" %>
<%@ Import Namespace="Telerik_controls_test" %>
<script RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        Application["usercount"] = 0;
    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }
    void Session_Start(object sender, EventArgs e)
    {

        Application.Lock();
        Application["usercount"] = (int)Application["usercount"] + 1;
        Application.UnLock();
    }

    void Session_End(object sender, EventArgs e)
    {
        Application.Lock();
        Application["usercount"] = (int)Application["usercount"] - 1;
        Application.UnLock();
    }
</script>


Step 2:- Design web form .aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblno_of_user" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Step 3:- Logic on .Cs Page

protected void Page_Load(object sender, EventArgs e)
    {
        lblno_of_user.Text = "Count Login User: " +
Convert.ToString(Application["usercount"]);
    }

Step 4:- Configuration in .Webconfig file

<system.web>
    <sessionState mode="InProc" cookieless="false" timeout="20"/>
</system.web>


It will look like :-




Comments

Popular posts from this blog

Create and save QR code in asp.net with C#

Change text of RadGrid Header Dynamically

Telerik Radwindow Open on Button Click