因为访问量大,做页面浏览量的时候不能直接操作库;用文件来记录的话,虽然减缓了数据库的压力但是对服务器I/O却是一个考验;而缓存正是.Net的一大优势,所以想出HttpHandler结合Cache来减缓I/O操作,这样I/O跟数据库的压力都解决了!

首先创建统计类库

1.创建CounterHelper统计类
  1利用HttpHandler和Cache统计点击量using System;
  2利用HttpHandler和Cache统计点击量using System.Web;
  3利用HttpHandler和Cache统计点击量using System.Web.Caching;
  4利用HttpHandler和Cache统计点击量using System.Collections.Specialized;
  5利用HttpHandler和Cache统计点击量using System.Data;
  6利用HttpHandler和Cache统计点击量using System.Data.SqlClient;
  7利用HttpHandler和Cache统计点击量using System.Configuration;
  8利用HttpHandler和Cache统计点击量using System.Text;
  9利用HttpHandler和Cache统计点击量using System.IO;
 10利用HttpHandler和Cache统计点击量
 11利用HttpHandler和Cache统计点击量namespace MYSpace.Counter
 12

2.创建HttpHandler
 1利用HttpHandler和Cache统计点击量using System;
 2利用HttpHandler和Cache统计点击量using System.Web;
 3利用HttpHandler和Cache统计点击量using System.Text.RegularExpressions;
 4利用HttpHandler和Cache统计点击量
 5利用HttpHandler和Cache统计点击量namespace MYSpace.Counter
 6

生成dll后创建一个Website,然后把dll引用进来!
接着在web.config里面添加配置:
    <httpHandlers>
      <add verb="*" path="count.aspx" type="MYSpace.Counter.CounterHandler,MYSpace.Counter" />
    </httpHandlers>


最后在web页面调用就ok了。页面代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <SCRIPT LANGUAGE="JavaScript" src='count.aspx?id=o4'></SCRIPT>
</head>
<body>
    <form >
    <div>
   
    </div>
    </form>
</body>
</html>
很简单吧,这里只介绍到写入文件,如果想写入库里面,直接读取文件里的数值就搞定!

相关文章:

  • 2021-04-07
  • 2021-09-29
  • 2021-12-03
  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-20
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案