如何统计在线人数
2013-04-24 11:21
309 查看
<%@ Application Language="C#" %> <%@ Import Namespace="System.IO" %> <script runat="server"> void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 string filepath = Server.MapPath("~/App_Data/Count.txt"); if (!File.Exists(filepath)) { StreamWriter sw = new StreamWriter(filepath); sw.WriteLine(0); sw.Flush(); sw.Close(); } StreamReader sr = new StreamReader(filepath); int intFwl = int.Parse(sr.ReadLine()); sr.Close(); Application["Fwl"] = intFwl; Application["Online"] = 0; } void Application_End(object sender, EventArgs e) { // 在应用程序关闭时运行的代码 string filepath = Server.MapPath("~/App_Data/Count.txt"); StreamWriter sw = new StreamWriter(filepath); sw.WriteLine(Application["Fwl"]); sw.Flush(); sw.Close(); } void Application_Error(object sender, EventArgs e) { // 在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e) { // 在新会话启动时运行的代码 Application["Fwl"] = int.Parse(Application["Fwl"].ToString()) + 1; Application["Online"] = int.Parse(Application["Online"].ToString()) + 1; Session.Timeout = 5; string filepath = Server.MapPath("~/App_Data/Count.txt"); StreamWriter swFile = new StreamWriter(filepath); swFile.WriteLine(Application["Fwl"]); swFile.Flush(); swFile.Close(); } void Session_End(object sender, EventArgs e) { // 在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer // 或 SQLServer,则不会引发该事件。 Application["Online"] = int.Parse(Application["Online"].ToString()) - 1; } </script> 在线 和 来访人数 上面全体复制到 Global.asax 分割线---------------------------------------------------------------------------------------------- 下面是显示出来的 添加到你需要的页的cs文件里面 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sFwl = Application["Fwl"] != null ? Application["Fwl"].ToString() : "N"; string sOnline = Application["Online"] != null ? Application["Online"].ToString() : "N"; for (int i = 0; i < sFwl.Length; i++) { Label1.Text += "<img src='images/count/" + sFwl[i] + ".png'/>"; } for (int i = 0; i < sOnline.Length; i++) { Label2.Text += "<img src='images/count/" + sOnline[i] + ".png'/>"; } } }
相关文章推荐
- 如何实现在线人数统计和登录限制?
- 如何实现 网站在线人数以及历史访问人数的统计
- 如何统计每个小时用户在线人数?
- .Net如何统计在线人数
- 如何处理多人同时登录同一个账号以及如何统计在线人数和访问量?
- .Net如何统计在线人数
- 专题:如何实现 网站在线人数以及历史访问人数的统计
- .Net如何统计在线人数
- .Net如何统计在线人数
- 如何使用Servlet监听器实现网站在线人数统计
- .Net如何统计在线人数
- .Net如何统计在线人数
- .Net如何统计在线人数
- .Net如何统计在线人数
- 如何统计在线的人数
- .net如何统计在线人数
- Servlet中如何捕获Session事件(统计在线人数)
- .Net如何统计在线人数
- 关于jsp内置对象Session和Cookie使用的肤浅理解,如何使用Session来统计网站在线人数
- .net如何统计在线人数