[This is preliminary documentation and subject to change]

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 NamesDescription
Pagecnt.dllThe Page Counter component.
Hit Count Data fileThe text file to which the Page Counter component saves the current hit count.

Syntax

SetoVar= 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 ValueDescription
File_LocationA 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_CountA 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
HitsDisplays the number of times that a specified URL has been opened.
PageHitIncrements the Hit Count.
ResetSets 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 tenth visitor.

--- PageCount.asp ---

<% 
  Set MyPageCounter = Server.CreateObject("MSWC.PageCounter")
  HitMe = MyPageCounter.Hits
  If HitMe = 10 Then 
%>
  You are the lucky 10th Customer!!! <BR>
<% Else %>
  Sorry, you are customer #<%= HitMe %> <BR>
<% End If %>

© 1997-2001 Microsoft Corporation. All rights reserved.