Creating a Hit Counter in ASP.NET

Remember the ASP Classic Hit Counter? You’d create a text file for each page you wanted to record that page’s hits. To start with, you’d just type in a zero to begin the counting process. Then, you’d put this code in your ASP document:

Set fs = CreateObject("Scripting.FileSystemObject") CounterPage = Server.MapPath ("/counters/YourASPDoc.cnt") Set a = fs.OpenTextFile(CounterPage) ct = CLng(a.ReadLine) ct = ct + 1 a.Close Set a = fs.CreateTextFile(CounterPage, True) a.WriteLine (ct) a.Close Response.Write ct

Continues…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>