How to effectively prevent the same account from repeatedly logging on to the system

Source: Internet
Author: User

Maintain an Online table and check whether there is a logon. You are not allowed to log on again. You can use Sessionid as the unique identifier. You can also generate a GUID and send it to the COOKIE to distinguish different clients, and add JS, it can achieve better results, such as automatic offline after leaving.

The solution code is as follows:

 

Public virtual void Application_Start (object sender, EventArgs e)
{
// Reset the mailer indicator
Application ["MailerStatus"] = "All Mailings Complete ";

// Initialize a datatable for users online
DataTable objUserTable = new DataTable ();
ObjUserTable. Columns. Add ("SessionID", System. Type. GetType ("System. Guid "));
ObjUserTable. Columns. Add ("PeopleID", System. Type. GetType ("System. Int32 "));
ObjUserTable. Columns. Add ("ShowDetail", System. Type. GetType ("System. Boolean "));
DataColumn [] pk = new DataColumn [1];
Pk [0] = objUserTable. Columns [0];
ObjUserTable. PrimaryKey = pk;
Application ["UserTable"] = objUserTable;
}

/**////
/// The Session_Start event adds user session information
/// Application ["UserTable"].
///
Public virtual void Session_Start (object sender, EventArgs e)
{
Application. Lock ();
// Application. Lock ();
DataTable objUserTable = (DataTable) Application ["UserTable"];
DataRow objRow = objUserTable. NewRow ();
Guid objGuid = Guid. NewGuid ();
ObjRow [0] = objGuid;
Session ["PfSessionID"] = objRow [0];
ObjRow [1] = 0;
ObjRow [2] = false;
ObjUserTable. Rows. Add (objRow );
Application ["UserTable"] = objUserTable;
Application. UnLock ();
}


/**////
/// The Session_End event deletes user session information from
/// Application ["UserTable"].
///
Public virtual void Session_End (object sender, EventArgs e)
{
Application. Lock ();
DataTable objUserTable = (DataTable) Application ["UserTable"];
ObjUserTable. Rows. Find (Guid) Session ["PfSessionID"]). Delete ();
Application ["UserTable"] = objUserTable;
Application. UnLock ();
}
 

Related Article

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.