Limit your account and sign in-asp.net

Source: Internet
Author: User

///Login PageHashtable Haol = (Hashtable) application["oltable"]; if(Haol = =NULL) {Haol=NewHashtable (); application["oltable"] =Haol; }                Else{HttpCookie Cookie=NewHttpCookie ("Zinfo");//define a Cookie object and an item named info                    if(request.cookies["Info"] !=NULL) {request.cookies["Info"]. values["Userhotleid"] =Sessioninclude.userbranchid; //cookies. Values.add ("Userhotleid", Sessioninclude.userbranchid);Response.appendcookie (cookie);//determine the Write cookie                    }                    Else{cookie. Values.add ("Userhotleid", Sessioninclude.userbranchid); Response.appendcookie (cookie);//determine the Write cookie                    }                    //Current User IDGuid key =Guid.NewGuid (); session["UserKey"] =key; IDictionaryEnumerator list=Haol.                    GetEnumerator (); ArrayList ls=NewArrayList ();  while(list. MoveNext ()) {if(list. value.tostring () = =SessionInclude.SessionId.Trim ()) {ls. ADD (list.                            Key); //Haol. Remove (list. Key);                        }                    }                    inti = ls. Count-1;  while(I >-1) {application.lock (); Haol.                        Remove (Ls[i]);                        Application.UnLock (); I= i-1;                    } application.lock (); Haol.                    ADD (Key, SessionInclude.SessionId.Trim ()); application["oltable"] =Haol;                Application.UnLock (); }
///All page Inheritance Classes Public classbasepage:system.web.ui.page{protected Override voidOnLoad (EventArgs e) {Base.    OnLoad (e); }    Override protected voidOnInit (EventArgs e) {basepageinitinfo (); } Public voidBasepageinitinfo () {Try{Hashtable Haol= (Hashtable) application["oltable"]; if(Haol = =NULL) {Haol=NewHashtable (); application["oltable"] =Haol; }            Else            {                if(session["UserKey"] !=NULL)                {                    //Current User KeyGuid key =NewGuid (session["UserKey"].                    ToString ()); IDictionaryEnumerator Val=Haol.                    GetEnumerator ();  while(val.) MoveNext ()) {if(Val.) Value.tostring (). Trim () = =SessionInclude.SessionId.Trim ()) {Guid Currguid=NewGuid (val.                            Key.tostring ()); if(!currguid.equals (Key))                                {Application.Lock (); Haol. Remove (session["UserKey"].                                ToString ()); session["UserKey"] =NULL;                                Application.UnLock (); Response.Write ("<script>alert (' Your account is logged in elsewhere, you are forced to downline '); window.parent.location= '. /login.aspx ';</script>");  Break; }                        }                    }                }                Else                {                    //Current User IDGuid key =Guid.NewGuid (); session["UserKey"] =key; IDictionaryEnumerator list=Haol.                    GetEnumerator (); ArrayList ls=NewArrayList ();  while(list. MoveNext ()) {if(list. value.tostring () = =SessionInclude.SessionId.Trim ()) {ls. ADD (list.                            Key); //Haol. Remove (list. Key);                        }                    }                    inti = ls. Count-1;  while(I >-1) {application.lock (); Haol.                        Remove (Ls[i]);                        Application.UnLock (); I= i-1;                    } application.lock (); Haol.                    ADD (Key, SessionInclude.SessionId.Trim ()); application["oltable"] =Haol;                Application.UnLock (); }            }        }        Catch{}}}


Article turned from: http://www.cnblogs.com/elves/p/4044947.html

Limit your account and sign in-asp.net

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.