µ±Ç°Î»Ö㺠´úÂëÃÔ >> ASP.NET >> ΪʲôϵͳҪÇóͬһ¸öÓû§ÔÚͬһʱ¼äÖ»ÄܵǼһ´Î²»³É¹¦½â¾ö·½·¨
  Ïêϸ½â¾ö·½°¸

ΪʲôϵͳҪÇóͬһ¸öÓû§ÔÚͬһʱ¼äÖ»ÄܵǼһ´Î²»³É¹¦½â¾ö·½·¨

Èȶȣº4208   ·¢²¼Ê±¼ä£º2013-02-25 00:00:00.0
ΪʲôϵͳҪÇóͬһ¸öÓû§ÔÚͬһʱ¼äÖ»ÄܵǼһ´Î²»³É¹¦
Ï£ÍûʵÏÖϵͳҪÇóͬһ¸öÓû§ÔÚͬһʱ¼äÖ»ÄܵǼһ´Î£¬µ«Ã»³É¹¦£¨¿ÉÒÔÓÃÒ»¸öÕ˺Åͬʱ³É¹¦µÇ¼ϵͳ£©£¬°ïÎÒ¿´¿´´íÎó³öÔÚÄÄÀ
Ò»¡¢Global.asaxÖеĴúÂ룺
  void Application_Start(object sender, EventArgs e)
  {
  Application["YZTonline"] = 0;//³ÌÐò¸Õ¿ªÊ¼µÄʱºòÉêÇëÒ»¸öÈ«¾Ö±äÁ¿

  }

  void Session_Start(object sender, EventArgs e)
  {
  Session.Contents["username"] = 0;
  }

  void Session_End(object sender, EventArgs e)
  {
  string strUserId = Session["username"] as string;
  ArrayList list = Application.Get("GLOBAL_USER_LIST") as ArrayList;
  if (strUserId != null && list != null)
  {
  list.Remove(strUserId);
  Application.Lock();
  Application["YZTonline"] = list.Count;
  Application.Add("GLOBAL_USER_LIST", list);
  Application.UnLock();
  }

  }

¶þ¡¢Web.ConfigÖеÄÅäÖôúÂ룺
<system.web>
  <globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
  <!--ÍøÒ³Ò³ÃæÎÞÂÒÂë-->

<sessionState mode="InProc" cookieless="true"/>
<compilation debug="true" targetFramework="4.0">
</compilation>

Èý¡¢µÇ¼ÑéÖ¤´úÂ룺
  string strUserId = this.txtusername.Text.ToString().Trim();
  ArrayList list = Application.Get("GLOBAL_USER_LIST") as ArrayList;
  if (list == null)
  {
  list = new ArrayList();
  }
  for (int i = 0; i < list.Count; i++)
  {
  if (strUserId == (list[i] as string))
  {
  Response.Write("<script>window.alert('ÄúÒѾ­µÇ¼ϵͳ¡£Èç·Ç¡°°²È«Í˳ö¡±·½Ê½¹Ø±Õϵͳ£¬ÇëÉÔºòƬ¿ÌÔÙ³¢ÊԵǼ¡£');</script>");
  return;
  }
  }
  long KeyNumber = Cooperate_Office.Old_App_Code.SmartWebServerScript.GetUserNumber();
  if (list.Count >= KeyNumber)
  {
  Response.Write("<script>window.alert('µ±Ç°µÇ¼µÄÓû§ÊýÒѾ­´ïµ½¿ª·¢ÉÌÔÊÐí×î´óµÇ¼Êý£¬ÇëÓ뿪·¢ÉÌÁªÏµ¡£');</script>");
  return;
  }
  list.Add(strUserId);
  Application.Lock();
  Application.Add("GLOBAL_USER_LIST", list);  
  Application["YZTonline"] = Convert.ToInt32(Application["YZTonline"]) + 1;
  Application.UnLock();

ÎÒ×Ô¼º¿´ÁËһϺÃÏñApplication.Add("GLOBAL_USER_LIST", list)ûÓÐÕýÈ·Ö´ÐУ¬listÖÐûÓÐÊý¾Ý¡£

------½â¾ö·½°¸--------------------------------------------------------
ͬһ¸öÓû§ÔÚͬһʱ¼äÖ»ÄܵǼһ´Î£¿

Â¥Ö÷Òâ˼ÊÇ Èç¹ûÓû§µÇ¼³É¹¦ºó£¬¾Í²»ÄÜÔٵǼÁËÂð£¿

¿ÉÒԵǼ³É¹¦ºó£¬¼Ç¼һ¸ösession£¬ Èç¹ûÓû§ÔٵǼ£¬ÅжÏÕâ¸ösessionÊÇ·ñÓÐÖµ¼´¿É
  Ïà¹Ø½â¾ö·½°¸