Asp.net Vb.net , access control concurrency -


hello guys trying make restriction on webapp runs on vb.net framework asp.net. in words, how can control permitted number of sessions.

the webapp works , want add "how many users can access webapp" if number of users "sessions" exceeded new coming users redirected site.

i have been working on few weeks... tried cookies , seasons , neither working

scenario: maximum users can access webapp 1

when launch second browser , start new session usernumber incremented 1 hence redirected "serverbusy" page...

however, if second browser opened new tab , accessed webapp bypass condition @ session_start , access webapp .

thank you.

here code

imports system.web  public class global_asax inherits system.web.httpapplication public shared maxusersallowance integer = 1 'total number of users can enter server public shared usernumber integer = 0 ' current number of users  sub application_start(byval sender object, byval e eventargs)     ' fires when application started end sub  sub session_start(byval sender object, byval e eventargs)     usernumber = usernumber + 1     dim mycookie new httpcookie("usernumber")     dim mycookie2 new httpcookie("access")     mycookie.value = usernumber     mycookie2.value = true     response.cookies.add(mycookie)     response.cookies.add(mycookie2)     if (request.cookies("usernumber") isnot nothing)         if (request.cookies("usernumber").value > 1)             if (request.cookies("access").value)                 response.redirect("~/serverbusy.aspx")             end if         end if     end if  end sub  sub application_beginrequest(byval sender object, byval e eventargs)   end sub sub application_authenticaterequest(byval sender object, byval e eventargs) end sub  sub application_error(byval sender object, byval e eventargs) end sub  sub session_end(byval sender object, byval e eventargs)  end sub  sub application_end(byval sender object, byval e eventargs)  end sub  sub application_init(byval sender object, byval e eventargs)  end sub sub application_dispose(byval sender object, byval e eventargs)  end sub  sub application_unload(byval sender object, byval e eventargs)  end sub  end class 

after reading article https://stackoverflow.com/a/6218525/1260204 , updating code, issue still exist user can webapp if open new tab on browser , connected

imports system.web  public class global_asax inherits system.web.httpapplication    sub application_start(byval sender object, byval e eventargs)     ' fires when application started     application("activesessions") = 0 end sub  sub session_start(byval sender object, byval e eventargs)      try         application.lock()          dim activesessions integer = cint(application("activesessions")) + 1         dim allowedsessions integer = 1         ' retrieve threshold here instead         application("activesessions") = activesessions          if activesessions > allowedsessions             system.web.httpcontext.current.response.redirect("~/serverbusy.aspx", false)         end if             application.unlock()     end try end sub  sub application_beginrequest(byval sender object, byval e eventargs)       dim livesessionscount integer = cint(application("livesessionscount")) end sub sub application_authenticaterequest(byval sender object, byval e eventargs)  end sub   sub session_end(byval sender object, byval e eventargs)      application.lock()     application("activesessions") = cint(application("activesessions")) - 1     application.unlock()   end sub  end class 

update, have solved issue tabs. adding session.abandon() in redirected page. half solution far can to... other half , if user closes browser x , need wait 20 minutes until session ends ... there away terminate session once user exit/kill page?


Comments