首先创建统计类库
1.创建CounterHelper统计类
1
using System;
2
using System.Web;
3
using System.Web.Caching;
4
using System.Collections.Specialized;
5
using System.Data;
6
using System.Data.SqlClient;
7
using System.Configuration;
8
using System.Text;
9
using System.IO;
10
11
namespace MYSpace.Counter
12
2
3
4
5
6
7
8
9
10
11
12
2.创建HttpHandler
1
using System;
2
using System.Web;
3
using System.Text.RegularExpressions;
4
5
namespace MYSpace.Counter
6
2
3
4
5
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>
很简单吧,这里只介绍到写入文件,如果想写入库里面,直接读取文件里的数值就搞定!