Page Counter Component

The Page Counter component creates a PageCounter object that counts and displays the number of times a Web page has been opened. At regular intervals the object writes the number of hits to a text file so that in the event of a server shutdown, the data is not lost. The Page Counter component uses an internal Central Management object to record how many times each page in the application has been opened.

When an instance of the PageCounter object is created on a page by using the Server.CreateObject method, the object retrieves the current hit count for the specified Web page from the Central Management object. The object can then be manipulated with the methods it exposes.

The Page Counter component uses the following files:

File Names
pagecnt.dll The Page Counter component.
Hit Count Data file   The text file to which the Page Counter component saves the current hit count.

Syntax

<% Set oVar = Server.CreateObject("MSWC.PageCounter") %> 
 

Parameters

oVar
Specifies the name of the PageCounter object created by the call to Server.CreateObject.

Registry Entries

The Page Counter adds the key MSWC.PageCounter to the registry when the object is compiled or registered. The key is added under HKEY_CLASSES_ROOT and contains the following named values.

Named Value Description
File_Location  A string that specifies the path and filename of the Hit Count Data file. The default filename is hitcnt.cnt. This file is located in your Windows directory.
Save_Count  A DWORD that specifies the number of hits before the hit count is saved to the Hit Count Data file. Note that this is the total number of hits, not the number of hits per page. The default value is 25.

Methods

Hits Displays the number of times that a specified URL has been opened.
PageHit Increments the Hit Count.
Reset Sets the hit count for a specified page to 0.

Example

The following example uses the PageCounter object to track the number of visitors to the page and sends a special message to the millionth visitor.

<% 
Set MyPageCounter = Server.CreateObject("MSWC.PageCounter")
HitMe = MyPageCounter.Hits

If HitMe = 1000000 Then 
%>
  You are the lucky 1,000,000th Customer!!! <BR>
<% Else %>
  Sorry, you are customer #<%= HitMe %> <BR>
<% End If %>
 

Note  This component is not installed with IIS. You can install it from the Microsoft Web site at: http://www.microsoft.com/iis/, or from the CD included with the IIS Resource Kit.