Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
1.16/5 (4 votes)
See more:
How to get the count of visitors visiting the website,without having database interaction
Posted
Updated 8-May-17 3:20am

u can use global.asax file for that like

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

    }

C#
void Session_Start(object sender, EventArgs e)
  {
      // Code that runs when a new session is started
      Session["suer"] =Convert.ToInt32( Application["Users"])+ 1;
      Application["Users"] = Session["suer"];
  }


then on page load

C++
Response.Write(Session["suer"].ToString());
 
Share this answer
 
Comments
Brij 2-May-11 6:24am    
Is there any specific requirement to use Session to store the count. I think Application variable is enough.
 
Share this answer
 
Comments
kiquenet.com 5-Nov-16 17:35pm    
fails page
Look here:
http://www.aspdotnetfaq.com/Faq/How-to-show-number-of-online-users-visitors-for-ASP-NET-website.aspx[^]

Write code in global.asax file which interacts with the entire application.
The sample code is given below:
C#
void Application_OnStart(Object Sender, EventArgs E)
        {
            Application["CurrentUsers"] = 0;
        }
        void Session_OnStart(object Sender, EventArgs E)
        {
            Application.Lock();
            Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) + 1;
            Application.UnLock();
        }
        void Session_OnEnd(object Sender, EventArgs E)
        {
            Application.Lock();
            Application["CurrentUsers"] = System.Convert.ToInt32(Application["CurrentUsers"]) - 1;
            Application.UnLock();
        }
 
Share this answer
 
Comments
nikdokht 13-Oct-12 8:10am    
i want this cod for silverlight can u help me?
Ashish Rathod-.Net Developer 11-Aug-14 9:01am    
Hello Sandeep Mewara Sir,

I have one question for that post, when i use that code in my local website and run that code and whenever session_end event fire after session_start event second time fire and the count is increased again so what can i do for that problem?, any suggestion? please let me know ..

Thanks & Regards,
Ashish Rathod
kiquenet.com 5-Nov-16 17:36pm    
using Google Analytics or Performance Counters ??

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