///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