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. Hit counter on a web page

Hit counter on a web page

Scheduled Pinned Locked Moved ASP.NET
helptutorialcsharpasp-net
7 Posts 3 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.
  • J Offline
    J Offline
    JacSophie
    wrote on last edited by
    #1

    Hi, I am a new user to ASP.NET and VS.NET and I need some help. I am also a new user to CodeProject as well. I am trying to find a simple way to add a hit counter on a web page (ASP.NET and VB.NET) in VS.NET 2005. I found this example "Fast ASP.NET Hit Counter with Full Digit Graphic File Support" By JediBaron. I tried it but something goes wrong. I get this error on line 59:

    Dim i As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(Request("src")))

    I really cannot figure out what is wrong and how to correct the problem. Any help will be appreciated. Thanks.

    H 1 Reply Last reply
    0
    • J JacSophie

      Hi, I am a new user to ASP.NET and VS.NET and I need some help. I am also a new user to CodeProject as well. I am trying to find a simple way to add a hit counter on a web page (ASP.NET and VB.NET) in VS.NET 2005. I found this example "Fast ASP.NET Hit Counter with Full Digit Graphic File Support" By JediBaron. I tried it but something goes wrong. I get this error on line 59:

      Dim i As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(Request("src")))

      I really cannot figure out what is wrong and how to correct the problem. Any help will be appreciated. Thanks.

      H Offline
      H Offline
      HarrisonB
      wrote on last edited by
      #2

      This is off the top of my head. In your global.asax do this Sub Application_Start(ByVal sender AsObject, ByVal e As EventArgs) Application("Hits") = 0 EndSub Sub Session_Start(ByVal sender AsObject, ByVal e As EventArgs) 'Lock the Application for concurrency issues Application.Lock() 'Increment the counter Application("Hits") = Application("Hits") + 1 'Unlock the Application Application.UnLock() EndSub Than put this in your web form <%=application("Hits")%> times.

      A J 2 Replies Last reply
      0
      • H HarrisonB

        This is off the top of my head. In your global.asax do this Sub Application_Start(ByVal sender AsObject, ByVal e As EventArgs) Application("Hits") = 0 EndSub Sub Session_Start(ByVal sender AsObject, ByVal e As EventArgs) 'Lock the Application for concurrency issues Application.Lock() 'Increment the counter Application("Hits") = Application("Hits") + 1 'Unlock the Application Application.UnLock() EndSub Than put this in your web form <%=application("Hits")%> times.

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        Also he needs to store the hit count in permanent storage, so that even if the application gets restarted, the value Remains.. :-D

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Windows7 API Code Pack
        Simplify Code Using NDepend
        Basics of Bing Search API using .NET

        J 1 Reply Last reply
        0
        • H HarrisonB

          This is off the top of my head. In your global.asax do this Sub Application_Start(ByVal sender AsObject, ByVal e As EventArgs) Application("Hits") = 0 EndSub Sub Session_Start(ByVal sender AsObject, ByVal e As EventArgs) 'Lock the Application for concurrency issues Application.Lock() 'Increment the counter Application("Hits") = Application("Hits") + 1 'Unlock the Application Application.UnLock() EndSub Than put this in your web form <%=application("Hits")%> times.

          J Offline
          J Offline
          JacSophie
          wrote on last edited by
          #4

          Hi HarrissonB, This is a great start, but the counter gets reinitialized to 0 every time. There must be a simple way to store it somewhere and read the value from this data source. Now, I suppose there are many ways to store such a value, in a database (SQL Server, Access, etc.), in a text file or XLM file, and maybe some others. For a simple personal web site, what would be the best way (KISS method)? In a text file, would it be safe? Thanks.

          H 1 Reply Last reply
          0
          • J JacSophie

            Hi HarrissonB, This is a great start, but the counter gets reinitialized to 0 every time. There must be a simple way to store it somewhere and read the value from this data source. Now, I suppose there are many ways to store such a value, in a database (SQL Server, Access, etc.), in a text file or XLM file, and maybe some others. For a simple personal web site, what would be the best way (KISS method)? In a text file, would it be safe? Thanks.

            H Offline
            H Offline
            HarrisonB
            wrote on last edited by
            #5

            It will only get set to 0 when the web server is restarted but when the page is reloaded.

            J 1 Reply Last reply
            0
            • H HarrisonB

              It will only get set to 0 when the web server is restarted but when the page is reloaded.

              J Offline
              J Offline
              JacSophie
              wrote on last edited by
              #6

              Hi HarrisonB, The hit counter should never be reinitialized to 0, even when the server goes down. It should read its value from some data store where a start value could be set (<> 0) at the beginning. I think I can find some code where a xml file can be used. I will look it up and give you an answer as soon as I can. Thanks for your time.

              1 Reply Last reply
              0
              • A Abhishek Sur

                Also he needs to store the hit count in permanent storage, so that even if the application gets restarted, the value Remains.. :-D

                Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


                My Latest Articles-->** Windows7 API Code Pack
                Simplify Code Using NDepend
                Basics of Bing Search API using .NET

                J Offline
                J Offline
                JacSophie
                wrote on last edited by
                #7

                Hi Abhishek Sur, I do want to store the counter hits number in a data store, but cannot figure out how to do it. I have created a test database (DbTest) in SQL Server 2005 with a Param table and a simple column, NbHits. I can connect to it and display the number on a page. That is it. I would like my counter to be incremented every time a user visits the main page. I would also like to know which way is best for a simple personal web site. Do you know of some links where I could find some example? Thanks.

                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