ASP. NET

Source: Internet
Author: User

During web development, some systems require the same user to log on only once at the same time, that is, if a user has logged on, an error must be reported if the user logs on again before exiting.


A common solution is to determine whether the user already exists in the Application when logging on to the user. If the user exists, an error is reported. If the user does not exist, it is added to the Application (the Application is shared by all sessions, the unique object of the entire web application ):

The following is a reference clip:

  

String strUserId = txtUser. Text;

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 ))

{

// The error message is displayed when you have logged on.

LblError. Text = "this user has logged on ";

Return;

}

}

List. Add (strUserId );

Application. Add ("GLOBAL_USER_LIST", list );

Of course, you can use Cache and other storage methods here.

The next step is to remove the user from the Application when the user exits. We can handle it in the Session_End event of Global. asax:

The following is a reference clip:

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.