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 landing, the specific code is as follows: string key = TextBox1.Text;//user name text box is set to the cache keyword string uer = 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 did not log in if (Uer = = NULL | | uer = = String.Empty) {//define cache expiration Time TimeSpan sesst Imeout = new TimeSpan (0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0); The first time you 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 Login Response.Write ("<script>alert (' Your account has landed! '); window.location= ' login.aspx ';</script> ");}
Prevent the same user from logging in at the same time (using cache to solve the idea)