Function Description: User A logs on with aid. User B also uses aid to log on without exiting User A. At this time, user a is denied.
Add the following code to global. asax:
Void application_acquirerequeststate (Object sender, eventargs e) {If (request ["mycookies"]! = NULL & session ["ID"]! = NULL) {httpcookie cookie = request. Cookies ["mycookies"]; If (cookie [session ["ID"]. tostring ()]! = NULL) {If (application [session ["ID"]. tostring ()]. tostring ()! = Cookie [session ["ID"]. tostring ()]. tostring () {timespan Ts = new timespan (-1, 0, 0, 0); cookie. expires = datetime. now. add (TS); response. appendcookie (cookie); Session ["ID"] = NULL; request. cookies. remove ("mycookies") ;}}} on the page for permission verification (wait for the incoming window)
Protected void button#click (Object sender, eventargs e) {If (request. Cookies ["mycookies"]! = NULL) {If (session ["ID"]! = NULL) {If (session ["ID"]. tostring ()! = This. textbox1.text) {res_cookie ();} else {response. Write ("Login successful! ") ;}} Else {res_cookie ();}}
Private void res_cookie () {string this_time = datetime. now. tostring (); application [this. textbox1.text] = this_time; httpcookie cookie = new httpcookie ("mycookies"); timespan Ts = new timespan (0, 0, 1, 0); cookie. values. add (this. textbox1.text, this_time); Session ["ID"] = This. textbox1.text; response. appendcookie (cookie); response. write ("Logon successful! ");} Add a test button:
Protected void button2_click (Object sender, eventargs e) {If (request. Cookies ["mycookies"] = NULL) {response. Write ("Logon Failed! ");} Else {response. Write (" Logon successful! ") ;}} Finally, release the data in the application in the session_end event.