惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
D
Docker
T
The Blog of Author Tim Ferriss
罗磊的独立博客
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
J
Java Code Geeks
Jina AI
Jina AI
博客园 - 【当耐特】
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
Last Week in AI
Last Week in AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

博客园 - Lavenders

Java 正则表达式 量词 --- 三种匹配模式【贪婪型、勉强型、占有型】 信号量与PV操作 java的(PO,VO,TO,BO,DAO,POJO)解释 更新记录后关闭子窗口并刷新父窗口的Javascript jquery jqPlot API 中文使用教程 一款基于bootstrap的datetimepicker ASP.NET下CKEditor3.6.4结合CKFinder2.3实现文本编辑器的上传功能 VS2010创建Web Service程序 【原创】VS2010中水晶报表与VS2008水晶报表版本冲突问题 【转】XSL和XSLT jQuery历史版本 【转】让Iframe自适应高度 【转】框架集中framespacing、border和frameborder属性的关系 【转】Meta标签详解 ASP.NET保存信息总结(Application、Session、Cookie、ViewState和Cache等) . 【原创】VS2008 Web应用程序带数据库制作安装程序 asp.net中的缓存(三)应用程序数据缓存 asp.net中的缓存(二)局部数据缓存 asp.net中的缓存(一)页面输出缓存
使用Application对象简单完成网站总访问人数的统计
Lavenders · 2014-08-14 · via 博客园 - Lavenders

Global.asax文件:

using System.IO;
protected void Application_Start(object sender, EventArgs e)
        {
            FileStream fs = File.Open(Server.MapPath("counter.txt"),FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);
            Application["count"] = Convert.ToInt32(sr.ReadLine());
            sr.Close();
            fs.Close();
        }
//counter.txt会自动创建
        protected void Session_Start(object sender, EventArgs e)
        {
            Application.Lock();
            Application["count"] = (int)Application["count"] + 1;
            FileStream fs = File.Open(Server.MapPath("counter.txt"), FileMode.OpenOrCreate,FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(Application["count"]);
            sw.Close();
            fs.Close();
            Application.UnLock();
        }

此种方法是把总人数记录在一个记事本文件中,使用文件流读写的方式来更新人数值,较为简单。