ASP.NET判断用户是否在线

protected   void   Application_Start(Object   sender,   EventArgs   e)  
  {  
  Application["user_sessions"]   =   0;  
  }  
  protected   void   Session_Start(Object   sender,   EventArgs   e)  
  {  
  Application.Lock();  
  Application["user_sessions"]   =   (int)Application["user_sessions"]   +   1;  
  Application.Unlock();  
  }  
  protected   void   Session_End(Object   sender,   EventArgs   e)  
  {  
  Application.Lock();  
  Application["user_sessions"]   =   (int)Application["user_sessions"]   -   1;  
  Application.Unlock();

}

 

 

  private   void   Page_Load(object   sender,   System.EventArgs   e)  
  {    
  Visitors.Text   =   "本站当前有:   <b>"   +   Application["user_sessions"].ToString()   +   ""   +   "</b>   位访问者   !";  
  } 

posted @ 2009-04-22 15:49  ∮随风而行∮  阅读(1863)  评论(0编辑  收藏  举报