How does. Net restrict user logon?

Source: Internet
Author: User
Tags account security

Glossary
1. Cookies are translated as "dessert" by English words. This seems to have nothing to do with our computer. Cookies refer to a piece of information stored on a computer on a server.

2. The Session is translated as "Session" by English words. It exists in the memory of the server.

Scenarios where user logon is restricted
1. For example, after we log on to QQ in one place. If we log in again on another computer, the system will be kicked off the server.

2. The mailbox I used also has the above situation.

This is guaranteed to a great extent. Account Security.

How to Implement
Method 1: when a user logs on, the user's logon status is recorded in the database. Each time we log on to the database, we find whether the user is logged on. If you have logged on, perform relevant business operations.
Method 2: Put the user's logon status in the Session
Method 1 obviously has a disadvantage, assuming that the server is suddenly powered off. Is it a tragedy. The status of the logged-on user will be messy, and the user will not be able to log on again. Therefore, we choose Cookies and sessions to implement this scenario.

Sample Code

Copy codeThe Code is as follows:
If (Session ["LOGIN_USER_LIST"]! = Null)
{
Dictionary <Guid, UserInfo> Userlist = Session ["LOGIN_USER_LIST"] as Dictionary <Guid, UserInfo>;
Guid LoginKey = new Guid ();
Guid. TryParse (CookieHelper. getCookie ("LOG_USER_KEY"), out LoginKey );
If (Userlist. Keys. Contains (LoginKey ))
{
// How to log on
}
Else
{
// If the user does not log on
}


}

I hope the simple code above will help you.

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.