Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Count WebSite Visitors

Count WebSite Visitors

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheEagle
    wrote on last edited by
    #1

    Hi.. I wrote the following code to count my website visitors: (In the Global.asax) protected static int m_ActiveUsers; public static int ActiveUsers { get { return m_ActiveUsers; } } protected void Application_Start(Object sender, EventArgs e) { Application.Lock(); m_ActiveUsers=0; Application.UnLock(); } protected void Session_Start(Object sender, EventArgs e) { Application.Lock(); ++m_ActiveUsers; Application.UnLock(); } protected void Session_End(Object sender, EventArgs e) { Application.Lock(); --m_ActiveUsers; Application.UnLock(); } But the problem it doesnt give me the right number always.Some times this code tells me there is two visitors while there is no one except me.And some times it doesnt decrement the visitors count number when i exit. Do any one know how to make a better way that wont be affected by application errors and will solve my problem? "I am too late but i will never give up"

    S 1 Reply Last reply
    0
    • T TheEagle

      Hi.. I wrote the following code to count my website visitors: (In the Global.asax) protected static int m_ActiveUsers; public static int ActiveUsers { get { return m_ActiveUsers; } } protected void Application_Start(Object sender, EventArgs e) { Application.Lock(); m_ActiveUsers=0; Application.UnLock(); } protected void Session_Start(Object sender, EventArgs e) { Application.Lock(); ++m_ActiveUsers; Application.UnLock(); } protected void Session_End(Object sender, EventArgs e) { Application.Lock(); --m_ActiveUsers; Application.UnLock(); } But the problem it doesnt give me the right number always.Some times this code tells me there is two visitors while there is no one except me.And some times it doesnt decrement the visitors count number when i exit. Do any one know how to make a better way that wont be affected by application errors and will solve my problem? "I am too late but i will never give up"

      S Offline
      S Offline
      Suamal
      wrote on last edited by
      #2

      The problem is because session_onEnd event will not be fired while you logged out of the application or closes the window. (on session end)

      T 1 Reply Last reply
      0
      • S Suamal

        The problem is because session_onEnd event will not be fired while you logged out of the application or closes the window. (on session end)

        T Offline
        T Offline
        TheEagle
        wrote on last edited by
        #3

        Thank you for your respond... If this is true(closing the window by a user wont fire Session_onEnd event)what should i do? 1-Decrease the timeout attribute of the sessionstate in web.config file?. 2-Use another event handler(other than Session_End handler )?. :confused: "I am too late but i will never give up"

        S 1 Reply Last reply
        0
        • T TheEagle

          Thank you for your respond... If this is true(closing the window by a user wont fire Session_onEnd event)what should i do? 1-Decrease the timeout attribute of the sessionstate in web.config file?. 2-Use another event handler(other than Session_End handler )?. :confused: "I am too late but i will never give up"

          S Offline
          S Offline
          Suamal
          wrote on last edited by
          #4

          Please go through this article.I hope it will help you. http://codebetter.com/blogs/brendan.tompkins/archive/2005/01/25/48325.aspx

          T 1 Reply Last reply
          0
          • S Suamal

            Please go through this article.I hope it will help you. http://codebetter.com/blogs/brendan.tompkins/archive/2005/01/25/48325.aspx

            T Offline
            T Offline
            TheEagle
            wrote on last edited by
            #5

            I read the article.It is very useful but there are some problems that still exist for example using File menu>close to close the Browser window or transfer to another website in the same window. "I am too late but i will never give up"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups