Mencius Code . // The key, which is the unique identifier, must be unique. You can set rules as needed.
// For testing, the user name and password are used as the identification, and other error checks are not performed.
// Generate key
String Skey = Username. Text + " _ " + Password. text;
// Obtain the value of the given key in the cache.
String Suser = Convert. tostring (Cache [skey]);
// Check for existence
If (Suser = Null | Suser = String. Empty)
{
// If the project does not have this key in the cache, the table name user is not logged on or has timed out.
// Note that the following method of using the timespan constructor to overload the version is the key to determining whether to log on.
Timespan sesstimeout = New Timespan ( 0 , 0 , System. Web. httpcontext. Current. session. Timeout, 0 , 0 );
Httpcontext. Current. cache. insert (skey, skey, Null , Datetime. maxvalue, sesstimeout,
System. Web. caching. cacheitempriority. notremovable, Null );
Session [ " User " ] = Skey;
// The first time you log on, you can do what you want.
MSG. Text = " <H4 style = 'color: red'> Hi! Welcome to this site </H4> " ;
}
Else If (Session [ " User " ] ! = Null && Session [ " User " ]. Tostring () = Skey)
{
//Update the session time.
MSG. Text= "<H4 style = 'color: red'> logged on </H4>";
}
Else
{< br> // this user's record is found in the cache and the table name has been logged on, do not log on again
MSG. text = "
sorry, you seem to have logged on elsewhere:-(
" ;< br> return ;< BR >}