asp. net Simple implementation of single sign on of SSO
- 2021-07-10 19:25:16
- OfStack
This paper illustrates the simple implementation of single sign-on (SSO) by asp. net. Share it for your reference, as follows:
Single Sign-On (Single Sign On, SSO for short) is one of the most popular solutions for enterprise business integration. SSO enables users to access all application systems that trust each other only by logging in once in multiple application systems
CAS (Central Authentication Service) is a good single sign-on framework for Web applications (developed by Yale University) mainly used for Java Php are interested you can study under.
Here is a simple way to implement single sign-on:
public void SingleUserLogin(string userName){
// Define key value
string key=userName;
string value=Convert.ToString(Cache[key]);
if(value==null||value==string.Empty){
// Definition Cache Expired time
TimeSpan span=new TimeSpan(0,0,HttpContext.Current.Session.Timeout,0,0);
// No. 1 1 Insert on the second login 1 User-related cache Value,
HttpContext.Current.Cache.Insert(key,key,null,DateTime.MaxValue,span,System.Web.Caching.CacheItemPriority.NotRemovable,null);
Session["userName"]=userName;
Response.Redirect("Main.aspx");
}
else if(Cache[key].ToString()==key){
// Repeated landing
Response.Write("<mce:script type="text/javascript"><!--
alert(' Your account has been logged in !');window.location='login.aspx';
// --></mce:script>");
}
else{
// Cancel the current session Conversation
Session.Abandon();
}
}
Configuring Form Mode in Web Config
<authentication mode="Forms">//mode Value is Forms Validation for defined as a form
<forms loginUrl="Mananger/Login.aspx" name=".ASPXAUTH">// Users access first without logging in Mananger/Login.aspx Page
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
I hope this article is helpful to everyone's asp. net programming.