.net 网站首页,本次的项目中用到的一个网站首页中统计网页访问量的工具方法,我觉得它应该在pagebase里面,拿来用一下

需要建立一个根文件夹 ~/xml/couter.txt

#region 网站访问量         protected void pageviews() {             int count = 0;             //数据累加             int Stat = 0;             StreamReader srd;             //取得文件的实际路径             string file_path = Server.MapPath("/XML/counter.txt");             //打开文件进行读取             srd = File.OpenText(file_path);             while (srd.Peek() != -1) {                 string str = srd.ReadLine();                 count = int.Parse(str);             }             srd.Close();             // 在新会话启动时运行的代码             Application.Lock();             //获取Application对象中保存的网站总访问量             Stat = count;             Stat += 1;             object obj = Stat;             Application["counter"] = obj;             //将数据记录写入文件             StreamWriter srw = new StreamWriter(file_path, false);             srw.WriteLine(Stat);             srw.Close();             Application.UnLock();         }         #endregion
posted @ 2015-05-22 09:05  calochCN  阅读(181)  评论(0编辑  收藏  举报