Showing posts with label Global.asax. Show all posts
Showing posts with label Global.asax. Show all posts

Wednesday, May 27, 2015

In WebSite Find Online and Total Users Count

In websites we see online users and total user who visit the website. We may want to use this information in our websites. In Asp.net we can do it by using Global.asax to display it. To add it follow this way. File -> New-> Project-> Asp.net Web Application and add Global.asax.
Application State can save user counts.More information click link and get more info.



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

<script runat="server">
    
    
    public static int count = 0;
    void Application_Start(object sender, EventArgs e) 
    {
        Application["TotalUsers"] = count;
        Application["OnlineUsers"] = count;
    }
    
    void Application_End(object sender, EventArgs e) 
    {

       // Application["users"] = -1;

    }
        
       void Application_Error(object sender, EventArgs e)

    {

    Exception exception = Server.GetLastError();

    string message = "Error occurred in - " + Request.Url.ToString() + "and error message is - "

    + exception.Message + " Stack Trace - " + exception.StackTrace.ToString();
    }


    void Session_Start(object sender, EventArgs e) 
    {
        Application.Lock();
        count++;
        Application["OnlineUsers"] = count;
        Application["TotalUsers"] = count ;
       
        Application.UnLock(); 

       

    }

    void Session_End(object sender, EventArgs e) 
    {
       // count--;
        Application.Lock();
        Application["OnlineUsers"] = count - 1;
        Application.UnLock(); 
        

    }

       
</script>