VS2005下实现asp.net在线人数的统计
来源:互联网 发布:微博刷粉软件 编辑:程序博客网 时间:2024/05/16 07:03
首先在项目中选择“添加新项”,添加“Global.asax”全局变量文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.IO ;
namespace movie
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class Global : System.Web.HttpApplication
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
Application["conn"]="Server=localhost;database=movie;uid=sa;pwd='zcc';";
Application["user_sessions"] = 0;
Application["counter_num"]=0;
uint count=0;
StreamReader srd;
//取得文件的实际路径
string file_path=Server.MapPath ("counter.txt");
//打开文件进行读取
srd=File.OpenText (file_path);
while(srd.Peek ()!=-1)
{
string str=srd.ReadLine ();
count=UInt32.Parse (str);
}
object obj=count;
Application["counter"]=obj;
srd.Close ();
}
protected void Session_Start(Object sender, EventArgs e)
{
Application.Lock();
Application["user_sessions"] = (int)Application["user_sessions"] + 1;
Application.UnLock();
Application.Lock ();
//数值累加,注意这里使用了装箱(boxing)
uint jishu=0;
jishu=(uint)Application["counter"];
jishu=jishu+1;
object obj=jishu;
Application["counter"]=obj;
//将数据记录写入文件
string file_path=Server.MapPath ("counter.txt");
StreamWriter fs=new StreamWriter(file_path,false);
fs.WriteLine (jishu);
fs.Close ();
Application.UnLock ();
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
// Application.Lock();
// Application["counter_num"]=(int)Application["counter_num"]+1;
// Application.UnLock();
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
}
protected void Application_Error(Object sender, EventArgs e)
{
}
protected void Session_End(Object sender, EventArgs e)
{
Application.Lock();
Application["user_sessions"] = (int)Application["user_sessions"] - 1;
Application.UnLock();
}
protected void Application_End(Object sender, EventArgs e)
{
uint js=0;
js=(uint)Application["counter"];
//object obj=js;
//Application["counter"]=js;
//将数据记录写入文件
string file_path=Server.MapPath ("counter.txt");
StreamWriter fs=new StreamWriter(file_path,false);
fs.WriteLine(js);
fs.Close ();
}
#region Web 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
}
#endregion
}
}
- VS2005下实现asp.net在线人数的统计
- VS2005下实现asp.net在线人数的统计
- ASP.net 实现在线统计人数
- ASP.NET 实现统计在线人数
- Asp.Net实现在线人数统计
- Asp.Net实现在线人数统计
- ASP.net实现在线统计人数
- asp.net 实现在线人数统计
- asp.net的在线人数统计
- ASP.NET统计在线人数
- ASP.NET统计在线人数
- asp.net在线人数统计
- Asp.net在线统计人数
- asp.net统计在线人数
- asp.net统计在线人数
- Asp.net统计在线人数
- .net实现在线人数统计
- 使用ASP.NET的Application对象实现在线人数统计的功能
- 实现自己的音乐搜索软件(一)
- 经典sql语句
- 进制间的转换笔记
- ASP.NET中常用的26个优化性能方法
- OpenGL ES on iPhone OS
- VS2005下实现asp.net在线人数的统计
- 百度面试题及我的解答(4) 补class HashMethod1的代码
- ASP.NET 2.0 URL映射技巧
- 网站开发技巧大全
- 管理Fedora的服务
- Repeater嵌套使用实例
- 百度面试题及我的解答(4) 补 buffer模板类代码
- 微软官网进不去
- C#验证码