Background
First of all, to illustrate, the original requirement definition is that the same account can only have one person to log in, if the other login, the previous login is automatically kicked off. Originally wanted to make storage to the server database, but later if it is not normal to quit the next time you can not log in, this is on the Internet to find information to change the following east.
Landing Page Background
Login.aspx.cs//Single Sign-on judgmentHashtable honline = (Hashtable) application["Online"]; if(Honline! =NULL) { inti =0; while(I < Honline.count)//because of small bugs so increase this judgment, forcing the query to the end{idictionaryenumerator IdE=Honline.getenumerator (); stringStrkey =""; while(Ide.movenext ()) {if(Ide.value! =NULL&& idE.Value.ToString (). Equals (userinfo[0]. Userid.tostring ())) {//already loginStrkey =idE.Key.ToString (); Honline[strkey]="XXXXXX"; Break; }} I= i +1; } } Else{honline=NewHashtable (); } Honline[session.sessionid]= userinfo[0]. UserId; Application.Lock (); application["Online"] =Honline; Application.UnLock ();View Code
PS: This code can be placed directly into the login button, after the password is correct or not directly used.
Basic Page background (public page)
AsePage.aspx.cs//Single Sign-on judgmentHashtable honline = (Hashtable) application["Online"]; if(Honline! =NULL) {IDictionaryEnumerator IdE=Honline.getenumerator (); while(Ide.movenext ()) {if(Ide.key! =NULL&&idE.Key.ToString (). Equals (Session.SessionID)) {//already login if(Ide.value! =NULL&&"XXXXXX". Equals (IdE.Value.ToString ())) {honline.remove (Session.SessionID); Application.Lock (); application["Online"] =Honline; Application.UnLock (); stringJS ="<script Language=javascript>alert (' {0} ');p arent.window.location = ' {1} ' </script>";//Window.location.replace (' {1} ')Response.Write (string. Format (JS,"account has been logged in elsewhere, you will be forced to the downline (please keep your user password)! ", Resolveclienturl ("~/login.aspx"))); session["UserInfo"] =NULL; return; } Break; } } }View Code
PS: This code is the basis of judgment.
Results Demo
"C #" ASP. NET Web pages to add the single sign-on feature