void Application_Start(Object sender,EventArgs e)
{
int count=0;
System.IO.StreamReader srd;
//获取文件的实际路径
string file_path=Server.MapPath("counter.txt");
srd=System.IO.FileText(file_path);
while(srd.Peek()!=-1)
{
string str=srd.ReadLIne();
count=int.Parse(str);
}
srd.Close();
object obj=count;
Application["counter"]=obj;
}
void Session_Stat(Object sender,EventArgs e)
{
Application.Lock();
int Stat=0;
Stat=(int)Application["counter"];
Stat+=1;
object obj=Stat;
Application["counter"]=obj;
//将数据写入文件
string file_path=Server.MapPath("count.txt");
System.IO.StreamWriter srw=new System.IO.StreamWriter(file_path);
srw.WriteLine(Stat);
srw.Close();
Application.UnLock();
}
void Application_End(object sender,EventArgs)
{
int Stat=0;
Stat=(int)Application["counter"];
System.IO.StreamWriter srw=new System.IO.StreamWriter();
srw.WriteLine(Stat);
srw.Close();
}