CoverYourASP --> Losing my visitors --> Part 2

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
27 active users
2558 visitors today
2156 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2012 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

But you'll be pleasantly surprised to see that they always match - no matter how quickly you try to leave the page. This is because the script keeps running, even if the user has left the page.

This is an important point. If the user visits a page that requests 50,000 records from your database, then closes his browser, shuts down his computer and goes home, your server is still patiently sending carefully formatted HTML to his IP address! This is again getting off the point of this article, but to detect if a user is still listening when performing a lot of work on a page you may want to sprinkle some of these around:

// is user still waiting for this page?
if ( !Response.IsClientConnected ( ) )
{
   // no, so lets quit
   Response.Clear ( );    // clear buffer
   Response.End ( );    // quit processing
}

The code above only helps if you're doing a lot of processing - chances are that even with this code you'll still get the same number of headers and footers viewed! Aaaaaah! This time it's because you're probably using Response.Buffer = true; and the script executes very quickly. The time is really spent sending the HTML down the 28.8k modem the user is using.

So, using the above method won't work, but a very similar one will. Move the code that increments the footer counter into a new file, then call it client-side as an image, the same way my counter works. This means that the header gets incremented when the script starts processing, and the footer is incremented when the user has downloaded all the HTML, which is actually what you care about.

Part 3: The CountLosses.asp file...

Featured sponsor
My favorite resources


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!