Using Barcode printer for ASP.NET Control to generate, create EAN13 image in ASP.NET applications.

www.OnBarcode.com

You can designate a page for counting by tweaking one of the application s web.config files. In particular, you must turn on the enabled attribute in the <pageCounters> section. The page counter is disabled by default. Depending on the scope of the tweaked web.config file, all pages or a group of pages can be designated for counting.

Using Barcode encoder for Word Control to generate, create UPC Symbol image in Office Word applications.

www.OnBarcode.com

Enabling the page view tracking doesn t significantly affect overall page performance. The site counter service is implemented as an HTTP module. This module intercepts the Application_EndRequest event and writes data out to the site provider. As a result, counter data is written only when the request has completed and doesn t affect generation of the markup. The time taken to log counters is negligible compared to the time needed to render page content to the client, even for very simple pages.

Using Barcode decoder for VS .NET Control to read, scan read, scan image in .NET applications.

www.OnBarcode.com

In addition to using counters declaratively from pages and server controls, you can also update counters programmatically. You use the static members of the SiteCounters class, which represents the public API for reading and writing counter data. The following code shows how you can write data when a few controls are clicked on a page:

The value associated with each list item is written to the counter database when the corresponding item is clicked. The Write method of the SiteCounters class has several overloads. The one we use here requires you to specify the counter group, the counter name, some text that describes the event, the target URL (if any), and whether you want the application name and page URL be tracked. In this case, we write some optional information associated with the event the feedback. This information, known as the counter event data, is coded as a string and can be useful for grouping data, as you ll see in moment. The SiteCounters class has a few methods for extracting data from the provider s database. For example, the GetRows methods returns a DataSet object filled with the whole site counter table. Figure 8-12 shows the actual content of the DataSet in the sample application (rendered in a GridView).

Figure 8-12 The DataSet object that contains the current snapshot of the site counter database

F08DR12

C08620245.fm Page 284 Tuesday, June 8, 2004 6:50 PM

Part III

Application Services

You get the data and bind it to a GridView control using the following code:

The GetRows method requires a time interval all records are selected in the preceding snippet plus the counter group and counter name. Once you hold counter data as a DataSet, you can easily implement custom functions over the data. For example, you can calculate the average rate by summing the counter event data and dividing it by the total number of clicks:

The site counter service relies on the services of a site provider object to implement persistent data storage. ASP.NET 2.0 comes with two built-in providers one using an Access database and one using a SQL Server table. Script are provided to create and configure the databases off line. You can accomplish the same task through the visual interface of the Web Administration Tool integrated into Microsoft Visual Studio. ADO.NET classes are used to manage writing and reading on these tables. You can explore the structure of the default site counter table by looking at the aspnetdb.mdb file in the Data subdirectory of the application. The site counter table is named aspnet_SiteCounters.

Summary

Several times in this book, you ve seen the word codeless used in a discussion of programming to describe features that allow you to create relatively simple pages with no code at all. Will the day come when programmers become use-