"C #" ASP. NET Web pages to add the single sign-on feature

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.