2

I'm running a website with ASP.NET 4.0.

The CMS part of the website is made of plain ".HTML" pages, not ".aspx".

Question: apart from using awStats, is there a simple way to count how many times each page has been "served"?

Didier Levy
  • 3,393
  • 9
  • 35
  • 57
  • I'm sure someone will complain, but we have been using LogParser for quite a while to do specific queries such as this with no problem. It can even be automated with a little script or .NET app. – kpcrash Mar 20 '12 at 11:52

1 Answers1

5

Create an ashx handler that return an empty 1x1 pixel image and call it from the bottom of those pages as image with some parameters like the name of the page, or the id of this page.

Inside this handler save the statistics of the page call.

The way you call it is like an image, eg

<img src="keepstats.ashx?mypageinfo.html" height="1" width="1" alt="" >

and place it somewhere that is not affect the render of the page, and when the browser render the page load also this image/handler and you save your statistics. I let the height and width to 1x1 for avoid case that the browser not load it.

To make it even nicer, here is the code for the handler.

// 1x1 transparent GIF
private readonly byte[] GifData = {
    0x47, 0x49, 0x46, 0x38, 0x39, 0x61,
    0x01, 0x00, 0x01, 0x00, 0x80, 0xff,
    0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
    0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
    0x01, 0x00, 0x01, 0x00, 0x00, 0x02,
    0x02, 0x44, 0x01, 0x00, 0x3b
};

public void ProcessRequest (HttpContext context) 
{
    // save here your stat

    // send the image
    context.Response.ContentType = "image/gif";
    context.Response.Buffer = false;
    context.Response.OutputStream.Write(GifData, 0, GifData.Length);
}

Just take care for the cache, set the cache to none for this image.

Aristos
  • 66,005
  • 16
  • 114
  • 150