I saw on the Internet that Cache can be used to determine whether the user has logged in, which seems pretty good. After the experiment, the code
principle shared here is relatively simple:
Determine whether the specified customer login string already exists in the cache. If not, add it and specify its storage time in the cache. When logging in repeatedly, you can determine whether the user has logged in repeatedly by judging whether the cache value is empty.
//Generate Key
string sKey = TextBox1.Text + "_IsLogin";
//Get the value of the given Key in the Cache
string sUser = Convert.ToString(Cache[sKey]);
//Check if it exists
if (sUser == null || sUser == String.Empty)
{
//There is no item for this Key in the Cache, indicating that the user is not logged in, or the login has timed out.
//TimeSpan represents a time interval and obtains the system's setting value for session timeout.
//TimeSpan SessTimeOut = new TimeSpan(0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);
//(If it is considered that the time allowed for the user to log in again is less than the session timeout, this value can be set smaller, in this example it is set to one minute)
TimeSpan SessTimeOut = new TimeSpan(0, 0, 1, 0, 0);
HttpContext.Current.Cache.Insert(sKey, sKey, null, DateTime.MaxValue, SessTimeOut,
System.Web.Caching.CacheItemPriority.NotRemovable, null);
//After logging in for the first time, you can do the work you want to do.
Label1.Text = "Hello! Welcome";
}
else
{
//The user's record is found in the Cache. The table name has already been logged in. It is forbidden to log in again.
Label1.Text = "Sorry, you have logged in elsewhere. Or try again in 1 minute";
return;
}
http://www.cnblogs.com/heekui/archive/2006/12/14/591691.html