asp.net simple single sign on technology analysis

  • 2020-05-10 18:03:32
  • OfStack

The code is as follows:
 
/// Single sign-on (sso) (Single Sign On) 
public void SSOMethods(string username, string password) 
{ 
// Determine login status   Method omitted here...  
int result = CheckLogin(username, password); 
if(result>0) 
{ 
// only 1 Logo, can be set  
string key = string.Format("{0}_{1}",username, password); 
// get Cache In the key value  
string userCache = Cache[key].ToString(); 
// Judge if it is empty  
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> Login successful! </font>"); 
} 
else 
{ 
Repsonse.Write("<font color=red> Sorry, you are already logged in somewhere else! </font>"); 
return; 
} 
} 
else 
{ 
Response.Write(" Username does not exist! "); 
} 
} 

Related articles: