Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi all
I used this codes for get counter of users who visted my site
<%@ Application Language="C#" %>
 
<script runat="server">
 
    public static int totalNumberOfUsers = 0;
    public static int currentNumberOfUsers = 0;
    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["totalNumberOfUsers"] = 0;
        Application["currentNumberOfUsers"] = 0;
    }
    
    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        Application.Lock();
        Application["totalNumberOfUsers"] = ((int)Application["totalNumberOfUsers"] + 1);
        Application["currentNumberOfUsers"] = ((int)Application["currentNumberOfUsers"] + 1);
        Application.UnLock();
 
    }
 
    void Session_End(object sender, EventArgs e) 
    {
        Application.Lock();
        Application["currentNumberOfUsers"] = ((int)Application["currentNumberOfUsers"] - 1);
        Application.UnLock();
    }
       
</script>
 
But If 20 minutes elapsed without requested any page from website, then the counter goback to 0 ?? why ??
 
please help me
regards
Posted 28-Mar-13 3:00am
ocean99493
Comments
ryanb31 at 28-Mar-13 8:06am
   
First off, Session_End may only end after it times out so it is not an accurate way of counting users. Secondly, your app pool is probably set to reset after 20 minutes of idle time.
ocean99 at 28-Mar-13 8:08am
   
"Secondly, your app pool is probably set to reset after 20 minutes of idle time."
 
How can me modify this time??

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use in databing u will perfact result.
If U get ip address and Store In database u will best way to specific user wise visiter count.
OR
Each and Every time open your web site insert or update Query use in Database and U get Perfact Result.
  Permalink  
Comments
ocean99 at 28-Mar-13 8:12am
   
This is good idea,thank you, But now I want to use first method, any help please ?

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100