In Asp.net, the logon mutex-related code (does not include the process of exiting midway through)

Source: Internet
Author: User
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 >}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.