Click here to Skip to main content
14,843,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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["totalNumberOfUsers"] = ((int)Application["totalNumberOfUsers"] + 1);
        Application["currentNumberOfUsers"] = ((int)Application["currentNumberOfUsers"] + 1);


    void Session_End(object sender, EventArgs e) 
        Application["currentNumberOfUsers"] = ((int)Application["currentNumberOfUsers"] - 1);

But If 20 minutes elapsed without requested any page from website, then the counter goback to 0 ?? why ??

please help me
ZurdoDev 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 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

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.
Each and Every time open your web site insert or update Query use in Database and U get Perfact Result.
ocean99 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)

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