| to prevent the same user from logging in at the same time, the home page should record the information of the online user (Here we use the user name as an example), and then determine whether the Login User already exists. Here, we use a cache to store the user name that has been logged in. But the other question is, when do users leave the system? This requires that the content in the cache be cleared regularly, that is, set a cache time. This time can be associated with the user's session value. When the user's session value fails, the user's information in the cache will also be cleared. this achieves the effect of preventing simultaneous login. The Code is as follows: put the string key = textbox1.text; // set the username text box to the cache keyword. string uer = convert. tostring (Cache [Key]); // reads the user's value in the cache // determines whether the cache contains user information. If no relevant value exists, the user has not logged on If (uer = NULL | uer = string. empty) {< br> // defines the cache expiration time timespan sesstimeout = new timespan (0, 0, system. web. httpcontext. current. session. timeout, 0, 0); // insert a user-related cache value during the First Login, httpcontext. current. cache. insert (key, key, null, datetime. maxvalue, sesstimeout, system. web. caching. cacheitempriority. notremovable, null); session ["adminid"] = textbox1.text; response. redirect ("Main. aspx "); }< br> else {< br> // login again response. write (""); } |