Technical Analysis of asp.net simple single sign-on
Source: Internet
Author: User
The Code is as follows:
Copy codeThe Code is as follows: // Single Sign On)
Public void SSOMethods (string username, string password)
{
// This method is omitted to determine logon conditions ......
Int result = CheckLogin (username, password );
If (result> 0)
{
// Unique ID, which can be set by yourself
String key = string. Format ("{0 }_{ 1}", username, password );
// Obtain the key value in the Cache.
String userCache = Cache [key]. ToString ();
// Judge whether it is null
If (string. IsNullOrEmpty (userCache ))
{
TimeSpan SessionTimeOut = new TimeSpan (0, 0, HttpContext. Current. Session. TimeOut, 0, 0 );
HttpContext. Current. Cache. Insert (key, key, null, DateTime. MaxValue, SessionTimeOut, CacheItemPriority, NotRemovable, null );
Session ["User"] = key;
Response. Write ("<font color = red> logon successful! </Font> ");
}
Else
{
Repsonse. Write ("<font color = red> sorry, you have logged on elsewhere! </Font> ");
Return;
}
}
Else
{
Response. Write ("the user name does not exist! ");
}
}
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.