ASP server stats for html pages

后端 未结 1 1761
孤独总比滥情好
孤独总比滥情好 2020-12-20 01:20

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

相关标签:
1条回答
  • 2020-12-20 01:44

    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.

    0 讨论(0)
提交回复
热议问题