ASP.NET prohibit multi-user login [rpm]

Determine whether the user already exists in the Application, if there is on the error does not exist, then it is added to the Application (Application Session is common to all, the entire web application only one object):
The following is quoted fragment:
  String = strUserID txtUser.Text;
  the ArrayList List = Application.Get ( "GLOBAL_USER_LIST") AS the ArrayList;
  IF (List == null)
  {
  List new new = the ArrayList ();
  }
  for (int I = 0; I <list.Count; I ++)
  {
  IF (strUserID == (List [I] AS String))
  {
  // have already been registered, an error message
  lblError.Text = "this user is already logged";
  return;
  }
  }
  list.add (strUserID);
  Application.Add ( "GLOBAL_USER_LIST", List);
 
 Of course, there can also be saved using the Cache and so on.
  The next step is to be removed when the user exits from this user Application, we can deal with in Session_End event in Global.asax:
The following is quoted fragment:
  void the Session_End (SENDER Object, EventArgs E)
  {
  // code to run at the end of the session.
  // Note: Only sessionstate mode in the Web.config file is set
  when // InProc, that pose a Session_End event. If the session mode is set to StateServer
  // or SQLServer, the event is not raised.
  the Session strUserID = String [ "SESSION_USER"] AS String;
  the ArrayList List = Application.Get ( "GLOBAL_USER_LIST") AS the ArrayList;
  IF (strUserID List = null = null &&!!)
  {
  list.Remove (strUserID);
  Application.Add ( "GLOBAL_USER_LIST", List);
  }
  }
  These are not the problem, the problem is that when the user directly point the close button in the browser have a problem. Because direct turned off, and will not trigger events Session expired immediately, that is, close your browser to log on board is not into it.
   There are two possible ways:
  1, the use of JavaScript way
  Adding some javascript code to each page:
以下是引用片段:
  function window.onbeforeunload()
  {
  if (event.clientX>document.body.clientWidth && event.clientY<0||event.altKey){
  window.open("logout.ASPx");
  }
  }

Reproduced in: https: //www.cnblogs.com/Tim_Liu/archive/2010/11/25/1887962.html

Guess you like

Origin blog.csdn.net/weixin_33810006/article/details/94724539