Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me to make Online counter and total visited using Asp.net with C#
I have this code
JavaScript
void Session_Start(object sender, EventArgs e)
  {
      // Code that runs when a new session is started
      ++Users.OnlineCounter;
      ++Users.TotalUsers;
  }
  void Session_End(object sender, EventArgs e)
  {
      --Users.OnlineCounter;
  }



and the users Class

C#
public class Users
{
	public Users()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    private static int onlineCounter;
    private static int totalUsers;

    public static int TotalUsers
    {
        get { return Users.totalUsers; }
        set { Users.totalUsers = value; }
    }

    public static int OnlineCounter
    {
        get { return Users.onlineCounter; }
        set { Users.onlineCounter = value; }
    }
}


but It didn't work
Posted

The problem here is that you are putting it in a class of your own. try putting these things in the Application variables like Application["onlineUsers"] & Application["TotalVisisted"]. Also you will need to write them to disk frequently in case the application pool get reset. you should be able to get the values back.
 
Share this answer
 
Comments
kareem salem 10-May-12 4:20am    
Thank you
VJ Reddy 15-May-12 4:37am    
Good answer. 5!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900