From: http://www.cnblogs.com/ly5201314/archive/2008/09/04/1284149.html
To prevent the same user from logging on 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.CodeAs follows:
Put it in the place where the login is successful:
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 se Sstimeout = 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 (" ");
}