www.webdeveloper.com
Results 1 to 2 of 2

Thread: session_end and prevent double username log on

  1. #1
    Join Date
    Sep 2004
    Posts
    1

    Question session_end and prevent double username log on



    i have an asp.net application which will limit for an example 10 users to log in at 1 time ( to control network traffic purpose).
    The 11th user who wanna log on have to hold on until the 1 of the first 10 users log out, the 11th user then will be able to log on to the website.

    So i need to detect numbers of active users who access my website.
    This is my coding for this event:

    in global.asax:
    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session is started
    Application("UserCount")+ = 1
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session ends
    Application("UserCount") -= 1
    End Sub

    In web.config:
    <sessionState
    mode="InProc"
    stateConnectionString="tcpip=127.0.0.1:42424"
    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
    cookieless="false"
    timeout="5"
    />

    In my logout page:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Session.Abandon()
    End Sub

    My question:
    The session.abandon will event session_end immediately if i logout with a proper way by clicking logout button and this will trigger application("usercount") -=1. However, Application("Usercount") -=1 will be trigger again after 5 minus which is the timeout set in web config for the session. So for example two users log in and i will get -2 for my 'application("usercount")' after all the two users log out.
    May i know why this happen? Or if there is any alternate way to get the same output? Please help.
    Besides that, is there a way to detect double usernames log on, which mean the same username is log on using the different machine on the same time?
    thanx alot...

    Regards,
    leeching

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    The problem is the session on end event is not reliable. It will not fire immediatly after a session ends. Also the session state is a bit unreliable. You would be better off setting this up from iis.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles