程序员的部落

导航

application session 记录网站总访问人数和在线人数

protected void Application_Start(Object sender,EventArgs e)
{
    SqlConnection con=new SqlConnection("server=.;database=countPeople;uid=sa;pwd=sa;");
    con.Open();
   SqlCommand cmd=new SqlCommand("select * from countPeople",con);
   int count=Convert.ToInt32(cmd.ExecuteScalar());
   con.Close();
   Application["totol"]=count;
   Application["online"]=0;
}

protected void Session_Start(Object sender,EventArgs e)
{
   Session.Timeout=1;
   Application.Lock();
   Application["online"]=(int)Application["online"]+1;
Application["totol"]=(int)application["totol"]+1;
Application.UnLock();
}

protected void Session_End(Object sender,EventArgs e)
{
   Application.Lock();
   Application["online"]=(int)Application["online"]-1;
   Application.UnLock();
}

protected void Application_End(Object sender,EventArgs e)
{
SqlConnection con=new SqlConnection("server=;database=countPeople;uid=sa;pwd=sa;");
con.Open();
SqlCommand cmd=new SqlCommand("update countPeople set num="+Application["totole"].ToString(),con);

cmd.ExecuteNoQuery();

con.Close();


}

posted on 2009-04-02 10:05  程序员的部落  阅读(364)  评论(0编辑  收藏  举报