"Go" ASP to prevent the same user from logging in at the same time

Source: Internet
Author: User
Tags httpcontext

To prevent the same user from landing at the same time, the home page should record the online user's information (here and the user name for example), and then determine whether the user is logged in exists. Here you use a cache to store the logged-in username, but there is one more question to know when the user left the system. This will periodically erase the contents of the cache, which is the time to set a cache. This time can be associated with the user's session value, just when the user session value expires when the user in the cache information will be emptied. This achieves the effect of preventing simultaneous landings.

The specific code is as follows:

stringkey = TextBox1.Text;//the user Name text box is set to the cache keywordstringUer = convert.tostring (Cache[key]);//read the user's corresponding value in the cache//determine if there is a user's information in the cache, if there is no relevant value, indicating that the user is not logged inif(Uer = =NULL|| Uer = =String.Empty) {//Define cache Expiration TimeTimeSpan sesstimeout =NewTimeSpan (0,0, System.Web.HttpContext.Current.Session.Timeout,0,0); //when you first log in, insert a user-related cache value,HttpContext.Current.Cache.Insert (Key, Key,NULL, DateTime.MaxValue, Sesstimeout, System.Web.Caching.CacheItemPriority.NotRemovable,NULL); session["Adminid"] =TextBox1.Text; Response.Redirect ("main.aspx");}Else{//Repeat loginResponse.Write ("<script>alert (' Your account has been logged in! '); window.location= ' login.aspx ';</script>");}

★ Reprint Please specify Source: http://www.cnblogs.com/zfanlong1314/archive/2012/01/17/2390457.html

"Go" ASP to prevent the same user from logging in at the same time

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.