To create Hit Counter in Asp.Net
-
Friends, Plse tell me how to create hit counter(should display in textbox or label) in Asp.Net using notepad. I dont want to have any database. When page loads texbox(or label) value should be incremented by 1. Plse help me... Thank you...
At the end of the day, you're going to end up using some sort of datasource. The simplest method would be to create a textfile (or preferrably XML if you know how to read it...) in your root directory for your web application. Read the text document on the page load using the System.IO.File.ReadAllText() method, assign the value to a variable on the page, increment it by one, save it back to the file using System.IO.File.WriteAllText() method and display the value to the label.
Daniel Minnaar Lead Software Developer
-
Friends, Plse tell me how to create hit counter(should display in textbox or label) in Asp.Net using notepad. I dont want to have any database. When page loads texbox(or label) value should be incremented by 1. Plse help me... Thank you...
If you have no DB, you need to store the number in a text file, and just write code that handles the case of two users trying to read/write it at once.
Christian Graus - Microsoft MVP - C++ "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 )
-
Friends, Plse tell me how to create hit counter(should display in textbox or label) in Asp.Net using notepad. I dont want to have any database. When page loads texbox(or label) value should be incremented by 1. Plse help me... Thank you...
U can add hit-counter to application state bag Application.Add("HitCount", 0); Now, u can retrieve this value any time, then do whatever u want & update the value int hitCount = Convert.ToInt32(Application["HitCount"]); hitCount++; Application["HitCount"] = hitCount;