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. i want to know the number hits customers are visting

i want to know the number hits customers are visting

Scheduled Pinned Locked Moved ASP.NET
csharpasp-net
13 Posts 4 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.
  • C Christian Graus

    then write some code to increment a counter every time a page loads.

    Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    S Offline
    S Offline
    Soumini Ramakrishnan
    wrote on last edited by
    #3

    I think the following code will help you. In your application folder create a text file named "Counter.txt" and put 0 in that file. Write the following in the code behind page. protected void Page_Load(object sender, EventArgs e) { myLabel .Text = counter(); } public string counter() { StreamReader re = File.OpenText(Server.MapPath("Counter.txt")); string input = null; string mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); int myInt = int.Parse(mycounter); myInt = myInt + 1; TextWriter tw = new StreamWriter(Server.MapPath("Counter.txt")); tw.WriteLine(Convert.ToString(myInt)); tw.Close(); re = File.OpenText(Server.MapPath("Counter.txt")); input = null; mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); return mycounter; }

    C N 2 Replies Last reply
    0
    • S Soumini Ramakrishnan

      I think the following code will help you. In your application folder create a text file named "Counter.txt" and put 0 in that file. Write the following in the code behind page. protected void Page_Load(object sender, EventArgs e) { myLabel .Text = counter(); } public string counter() { StreamReader re = File.OpenText(Server.MapPath("Counter.txt")); string input = null; string mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); int myInt = int.Parse(mycounter); myInt = myInt + 1; TextWriter tw = new StreamWriter(Server.MapPath("Counter.txt")); tw.WriteLine(Convert.ToString(myInt)); tw.Close(); re = File.OpenText(Server.MapPath("Counter.txt")); input = null; mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); return mycounter; }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #4

      Well, you should answer the OP, not me. This code also has some big issues. First of all, it is prone to crashing. Never use int.Parse, always use int.TryParse. It's also way too many lines, I could write it in a lot less. Finally, won't it crash if the file does not exist ?

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      S 1 Reply Last reply
      0
      • C Christian Graus

        Well, you should answer the OP, not me. This code also has some big issues. First of all, it is prone to crashing. Never use int.Parse, always use int.TryParse. It's also way too many lines, I could write it in a lot less. Finally, won't it crash if the file does not exist ?

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        S Offline
        S Offline
        Soumini Ramakrishnan
        wrote on last edited by
        #5

        then what is the best solution

        C 1 Reply Last reply
        0
        • S Soumini Ramakrishnan

          then what is the best solution

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #6

          A text file is an OK solution, if the website doesn't have a database behind it 1 - check if the file exists before you open it, if not create it 2 - use int.TryParse so that if the file is corrupt, it resets rather than blow up the site

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          S 1 Reply Last reply
          0
          • C Christian Graus

            A text file is an OK solution, if the website doesn't have a database behind it 1 - check if the file exists before you open it, if not create it 2 - use int.TryParse so that if the file is corrupt, it resets rather than blow up the site

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            S Offline
            S Offline
            Soumini Ramakrishnan
            wrote on last edited by
            #7

            Thank you

            1 Reply Last reply
            0
            • S Soumini Ramakrishnan

              I think the following code will help you. In your application folder create a text file named "Counter.txt" and put 0 in that file. Write the following in the code behind page. protected void Page_Load(object sender, EventArgs e) { myLabel .Text = counter(); } public string counter() { StreamReader re = File.OpenText(Server.MapPath("Counter.txt")); string input = null; string mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); int myInt = int.Parse(mycounter); myInt = myInt + 1; TextWriter tw = new StreamWriter(Server.MapPath("Counter.txt")); tw.WriteLine(Convert.ToString(myInt)); tw.Close(); re = File.OpenText(Server.MapPath("Counter.txt")); input = null; mycounter = ""; while ((input = re.ReadLine()) != null) { mycounter = mycounter + input; } re.Close(); return mycounter; }

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #8

              You need some kind of locking. This is not thread safe.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

              C 1 Reply Last reply
              0
              • A ajaych

                i want to know the number of hits my application is being hited.i am using asp.net2.0 with c#.

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #9

                Best method would be using services like Google analytics[^]. If you want to implement your own tracker, better use database to keep the information, you don't need to worry about thread safety. But keep it in mind, if the application is getting good hits, your database will become huge in size.

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                1 Reply Last reply
                0
                • N N a v a n e e t h

                  You need some kind of locking. This is not thread safe.

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #10

                  I was trying not to get too confusing :-)

                  Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  N 1 Reply Last reply
                  0
                  • C Christian Graus

                    I was trying not to get too confusing :-)

                    Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                    N Offline
                    N Offline
                    N a v a n e e t h
                    wrote on last edited by
                    #11

                    :)

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      then write some code to increment a counter every time a page loads.

                      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                      A Offline
                      A Offline
                      ajaych
                      wrote on last edited by
                      #12

                      i did not get.could u send me the sample code.i just want to display the number of hits in asmal table or in any graphical image

                      C 1 Reply Last reply
                      0
                      • A ajaych

                        i did not get.could u send me the sample code.i just want to display the number of hits in asmal table or in any graphical image

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #13

                        I'm sorry, someone gave code, I corrected it, if you can't work it out, then I don't know what else to say.

                        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                        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