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”?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Create an ashx handler that return an empty 1×1 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 1×1 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0