ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

ASP.NET version of "Hit Counter"

Here's a version of our classic hit counter script implemented in ASP.NET. I've implemented it as a custom user control in order to make it easy to use on a large number of pages. It works much in the same manner as our original sample and stores the counts in a file based on the hosting file's name with a .cnt appended to it. For example, if you use the control on a page named index.aspx, it stores the hit count for that page in index.aspx.cnt. It also stays true to the original and lets you select whether you want the count displayed as text or images. I've also added a new option to show no display at all.

The main issue most people will probably have is the standard anonymous users not being able to write to the folder containing web content. In order to fix this you should use explorer to change the permissions on the .cnt files to allow writing. Don't change the permissions on the whole folder. If you don't want to change permissions on each .cnt file then create a new folder to store them all, change permissions on that folder, and then modify the script to store the count files in that folder. A final option is to wait until I get our database driven counter converted to ASP.NET (now available).

The zip file below includes the ascx control, a sample aspx file that uses the control, and a sample count file. You can get the images in a zip file from here(5.3 KB).

Here's a zip file of the code (2.2 KB).

Play with the running version.

Back to the "Hit Counter" sample


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers