?
Solved

asp.net+ session_end

Posted on 2004-09-01
10
Medium Priority
?
1,064 Views
Last Modified: 2008-02-26
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 wana 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 number 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") = Application("UserCount") + 1
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the session ends
              Application("UserCount") = 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.RemoveAll()
End Sub

My question:
Is the session.RemoveAll() will trigger the session_end in global.asax so that it will minus the Application("UserCount") value?
What i have now is although i have logout will a proper way ( thats mean click on logout and trigger the session.removeall() ), but the session_end is depends on the timeout which is set in web.config.This mean the 11th user need to hold on for 5 minutes after 1 of the first 10 users log out.

Or any of you got any alternate way. Please help. Thanks.
Regards,
leeching

0
Comment
Question by:leeching
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 

Expert Comment

by:Sirusdv
ID: 11960340
It might be alot easier instead of doing a logout like that just set session experation timeout to 0 ( Session.Timeout = 10 )
0
 
LVL 7

Expert Comment

by:vnvk
ID: 11960591
use application_start and Applciation_end also for the same purpose.
I mean, copy the code in session_start to apllicaton_start and session_end to appliation_end

That might help you.
0
 

Accepted Solution

by:
madhukar_konda earned 375 total points
ID: 11960906
Why dont you use Session.Abandon in logout page?, which automatically fires Session_End.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 20

Expert Comment

by:ihenry
ID: 11979540
I totally agree with madhukar_konda, calling the Session.Abandon method should cancel the current session and raise the Session_End event immediately. However it won't happens even after Session.Abandon is called or reach the time out, unless you have stored something in the Session state and it has completed at least one request.

There's no easy way, I guess, to handle such scenario. It might be better to incorporate two timers using client-side javascript in your pages. When the browser is in idle too long, one of the timer become active and prompts the user that the session is going to expire soon. If there's no response from user the other timer that has longer interval will become active and postback the page automatically to execute server-side code to cancel the current session and redirect to login page.
0
 

Author Comment

by:leeching
ID: 11980785
thanx madhukar_konda, session abandon really event session_end immediately and trigger                 application("usercount") -=1..However, it will trigger Application("Usercount") -=1 again after 5 minus which is the timeout set in web config for the session. So for example three users log in and i will get -3 for my application("usercount") after all the three users log out.
May i know why this happen? Besides that, is it a way to detect double usernames log on, which mean the same username is log on on the different machine on the same time?
thanx...
0
 

Expert Comment

by:madhukar_konda
ID: 11993827
Sorry for delay in replying back. We got a long weekend. So delay in replying.

Yes it is possible to check same user logging in from different locations.

There are many ways to check this. One of the popular way is, making a flag when any user logs in. When ever a user logs in to the system, make a flag in the database table. But it purely depends on your situation. Some applications may allow same user logging in at the same time in different systems.

Other way is, prepare a temporary table, log all the users while logging in. Log login in time and logout time. Based on logout time you can find out whether the same user logged in at present or not.

If you can tell me your exact situation, will suggest a better way.

Thanks
Konda
0
 

Author Comment

by:leeching
ID: 11994364
i cant get the user logout time if the user idle for 5 minutes ( timeout set in web config ) or do not logout properly ( without clicking the logout button) .
The session value will be set to nothing.

Besides that, how about my problem regarding session.abandon and application("usercount").
I do alot of research but still cant get a proper way to solve it.
Please help.
0
 
LVL 7

Expert Comment

by:vnvk
ID: 11994414
better use tables in conjunction with session.
@madhukar_konda is right in approach for temp tables or table where u can store session details.

You can write code to fire sessio_abandon when all the window instances are clsoed. get rid of application("usercount"). Instead, store the session details in a temp table an wheever session_abandon or logout takes palce, update the details.

To check the number of logins, retrieve the count from DB where logouttime is null.

Using DB would help you u out for all ur issues
0
 

Expert Comment

by:madhukar_konda
ID: 12003848
What happend leeching? Any luck?
0
 

Author Comment

by:leeching
ID: 12013149
Can u all do me a favour?
May i know iziit after the session_end at global.asax, it will run back to session_start after the timeout period?
Because i found that although im at my logout page, it will loop back to session_start after the timeout period (which is 5 minutes later) by using breakpoint during debugging.
May be i still not familiar with .net. So still can't catch the way .net run.
Because of this, i get negative value for my application("UserCount") because it loop back to session start then to  session end and minus my application("UserCount") again after i logout and idle for 5 minutes(timeout) without closing the browser.
Thanx.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question