Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

asp.net - ASP server stats for html pages

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"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...