Did*_*evy 2 html asp.net statistics
我正在使用ASP.NET 4.0运行一个网站.
该网站的CMS部分由简单的".HTML"页面组成,而不是".aspx".
问题:除了使用awStats之外,还有一种简单的方法来计算每个页面被"服务"的次数吗?
创建一个ashx返回空的1x1像素图像的处理程序,并从这些页面的底部将其作为图像调用,其中包含一些参数,如页面名称或此页面的ID.
在此处理程序内部保存页面调用的统计信息.
你称它的方式就像一个图像,例如
<img src="keepstats.ashx?mypageinfo.html" height="1" width="1" alt="" >
Run Code Online (Sandbox Code Playgroud)
并将其放置在不影响页面呈现的位置,当浏览器呈现页面时,也会加载此图像/处理程序并保存统计信息.我让高度和宽度为1x1,以避免浏览器无法加载它.
为了使它更好,这里是处理程序的代码.
// 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);
}
Run Code Online (Sandbox Code Playgroud)
只需注意缓存,将缓存设置为无图像.