For some reason, in our app we encounter a situation where a user can log in only one place, which is what we usually call Single sign-on. Implementing single Sign-On in ASP is simple, and the main method and all the code are analyzed below. [/P] [P=25, NULL, left] implementation ideas [/p][p=25, NULL, left] using the function of the cache, we keep the user's login information in the cache and set the expiration time for the session to expire, so once the session expires, Our cache expires, and the cache is accessible to all users, so it is easier to save user information than a database. [/P]
[P=25, NULL, left]string SKey = username. Text.tostring (). Trim (); Get the value of the given key in the cache
String suser = Convert.ToString (Cache[skey]); Check for Presence
if (suser = = NULL | | suser = = String.Empty)
{
TimeSpan sesstimeout = new TimeSpan (0, 0, System.Web.HttpContext.Current.Session.Timeout, 0, 0);//Get Session Expiration Time
HttpContext.Current.Cache.Insert (SKey, SKey, NULL, DateTime.MaxValue, Sesstimeout, System.Web.Caching.CacheItemPriority.NotRemovable, NULL);//Place the value in the cache and click
Successful Login
}
else if (Cache[skey]. ToString () = = SKey)//If this account is already logged in
{
Clientscript.registerstartupscript (GetType (), "hint", "<script>alert (' Sorry, current user is logged in ');</script>");
Return
}
Else
{
Session.Abandon ();//This paragraph is mainly to avoid unnecessary errors that can not log in
}
Asp. NET Single Sign-on (code)