473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Counting Sessions

kpg
Hi all,

Ah yes, the age old counting session question.

sessionstate
mode="InProc"
timeout="5"

Sub Application_Start()
Application("ConcurrentUsers") = 0
End Sub

Sub Session_Start()
Application.Lock()
Application("ConcurrentUsers") += 1
Application.UnLock()
End Sub

Sub Session_End()
Application.Lock()
Application("ConcurrentUsers") = -= 1
Application.UnLock()
End Sub

All's well, At first arrival of the login page Trace shows
ConcurrentUsers = 1

After login I navigate to a page that displays the count.
Still OK, trace and a label shows ConcurrentUsers = 1.

Private Sub Page_Load()
lblUsers.Text = Application("ConcurrentUsers")
End Sub

I have an "Update" button which does nothing but causes a
post back to re-display the page.

Private Sub btnUpdate_Click()
'no code here
End Sub

Trace and txtUsers now shows session count = 0! The session_end
event has not fired yet the Application variable is reset to 0.

My thoughts are that this must be a known issue or I'm just
missing something very basic.

Aug 17 '06 #1
4 2168
Take a look at the System.Diagnostics namespace's Performance counters

If you create a counter and use that to keep track of everything, you can go
ahead and monitor everything from aotside of your application's context.

"kpg" wrote:
Hi all,

Ah yes, the age old counting session question.

sessionstate
mode="InProc"
timeout="5"

Sub Application_Start()
Application("ConcurrentUsers") = 0
End Sub

Sub Session_Start()
Application.Lock()
Application("ConcurrentUsers") += 1
Application.UnLock()
End Sub

Sub Session_End()
Application.Lock()
Application("ConcurrentUsers") = -= 1
Application.UnLock()
End Sub

All's well, At first arrival of the login page Trace shows
ConcurrentUsers = 1

After login I navigate to a page that displays the count.
Still OK, trace and a label shows ConcurrentUsers = 1.

Private Sub Page_Load()
lblUsers.Text = Application("ConcurrentUsers")
End Sub

I have an "Update" button which does nothing but causes a
post back to re-display the page.

Private Sub btnUpdate_Click()
'no code here
End Sub

Trace and txtUsers now shows session count = 0! The session_end
event has not fired yet the Application variable is reset to 0.

My thoughts are that this must be a known issue or I'm just
missing something very basic.

Aug 17 '06 #2
kpg
As =?Utf-8?B?RGF2aWQgSmVzc2Vl?= once said in
microsoft.public.dotnet.framework.aspnet
Take a look at the System.Diagnostics namespace's Performance counters

If you create a counter and use that to keep track of everything, you
can go ahead and monitor everything from aotside of your application's
context.
Great idea! I tried to create my own counter but found I needed
security rights to the registry, so I decided to simply read the
value in the "ASP.NET Applications", "Sessions Active" counter for
my application instance. This is all I ever wanted anyway.

Here's the code:

Dim objCounter As New System.Diagnostics.PerformanceCounter( _
"ASP.NET Applications",
"Sessions Active",
"_LM_w3svc_1_root_LSFB1")

lblUsers.Text = objCounter.RawValue.ToString

But I was shocked to find that this technique had the same exact
problem as my before. After hitting the update button the Active
Session count went to 0!

This, of course, prompted me to look very closey at my code.

In the page_load event I have:

If Not Page.IsPostBack Then
Session.Timeout = 20
End If

If I remove the Session.Timeout statement both techniques work
fine and give the same results - an accurate count of active
sessions.

I much prefer the performance counter technique and think it's
quite superior to the Application varailbe technique, I am
comfused as to why resetting the session timeout removes the
session, even from the NT perfromance counter who's job it is to
count sessions?

The session must be there, because session level variable retain
their value, in fact even (other) Application level varaibles
retian their value.

What's going on here?

BTW - I have a reason to set the session timeout, as I want
different users to have different timeouts. Perhaps there is
a more appropriate palce to change the session timeout value
to accomplish this that does not screw up the session count.
Aug 17 '06 #3
I decompiles the System.Web.SessionState.HttpSessionStateContainer to see
what really happens and couldn't find anything that would cause screwy
behavior with the Session, so I can't help ya there. I get the feeling,
however, that the timeout does not take effect until the page processing is
complete (that's an intuitive guess, so don't go to the bank on it). If
there any way you can place that code somewhere outside of the page? maybe
the global authenticated event?
"kpg" wrote:
As =?Utf-8?B?RGF2aWQgSmVzc2Vl?= once said in
microsoft.public.dotnet.framework.aspnet
Take a look at the System.Diagnostics namespace's Performance counters

If you create a counter and use that to keep track of everything, you
can go ahead and monitor everything from aotside of your application's
context.

Great idea! I tried to create my own counter but found I needed
security rights to the registry, so I decided to simply read the
value in the "ASP.NET Applications", "Sessions Active" counter for
my application instance. This is all I ever wanted anyway.

Here's the code:

Dim objCounter As New System.Diagnostics.PerformanceCounter( _
"ASP.NET Applications",
"Sessions Active",
"_LM_w3svc_1_root_LSFB1")

lblUsers.Text = objCounter.RawValue.ToString

But I was shocked to find that this technique had the same exact
problem as my before. After hitting the update button the Active
Session count went to 0!

This, of course, prompted me to look very closey at my code.

In the page_load event I have:

If Not Page.IsPostBack Then
Session.Timeout = 20
End If

If I remove the Session.Timeout statement both techniques work
fine and give the same results - an accurate count of active
sessions.

I much prefer the performance counter technique and think it's
quite superior to the Application varailbe technique, I am
comfused as to why resetting the session timeout removes the
session, even from the NT perfromance counter who's job it is to
count sessions?

The session must be there, because session level variable retain
their value, in fact even (other) Application level varaibles
retian their value.

What's going on here?

BTW - I have a reason to set the session timeout, as I want
different users to have different timeouts. Perhaps there is
a more appropriate palce to change the session timeout value
to accomplish this that does not screw up the session count.
Aug 17 '06 #4
kpg
As =?Utf-8?B?RGF2aWQgSmVzc2Vl?= once said in
microsoft.public.dotnet.framework.aspnet
I decompiles the System.Web.SessionState.HttpSessionStateContainer to
see what really happens and couldn't find anything that would cause
screwy behavior with the Session, so I can't help ya there. I get the
feeling, however, that the timeout does not take effect until the page
processing is complete (that's an intuitive guess, so don't go to the
bank on it). If there any way you can place that code somewhere
outside of the page? maybe the global authenticated event?
hmmmm...well I moved it to the previous page, the one that redirects,
to this page, and the session counter still gets zapped. I can watch
it using the performance console, as soon as "session.timeout = 20" is
executed the performance counter goes to 0 (from 1). If I have several
sessions active it will just decrement the counter.

Interestingly, let's assume the session has been abandoned (which IMO
it has not) then once I re-hit the server with the postback I would
expect it to be re-created - it is not. This tell me that the session
is really still there (which I know is the case).

This behavior is exhibited on both my development machine (WinXP Pro)
and the deployment server (Win2k).

It's not a big issue, just worrisome.

In the final product I won't be using session state anyway, but I would
still like an accurate (as possible) count of active sessions.

Aug 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mr_burns | last post by:
hi, i am wanting to count the number of unique rows under a certain column. i want to count how many times a page has been accessed. how i plan to do this is every time a page is accessed, a...
3
by: Antoni | last post by:
Hello, I was trying to write a simple shopping example, which allows the user to select two poducts and we kept a counter of each item. In this code, the sessions are created, but the files...
1
by: Sajid | last post by:
Hi, I'm developing an online shopping cart. Usually the site administrator modifies products etc in the "Store". I want a mechanism for the administrator such that he should be able to view or...
8
by: Mr. x | last post by:
Hello, I need a script for counting the no. of enters on my site, please. I need a check that for the same user in the same day - if the user enter several times, it is count once (or something...
3
by: BravesCharm | last post by:
BravesCharm Dec 7, 10:57 am show options Newsgroups: microsoft.public.dotnet.distributed_apps From: "BravesCharm" <mastrauc...@gmail.com> Date: 7 Dec 2004 10:57:40 -0800 Local: Tues, Dec...
2
by: Brad B. | last post by:
I am trying to enforce a licence for my web application based on the number of active sessions. Each time a new user accesses the app, I want to check this to see if over the limit. ...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
8
by: Mike P | last post by:
What would be the best way of counting the number of users who are currently logged on to a website? I am making the users login against a database of valid users. Would the best way be to add a...
2
by: pradeep | last post by:
Hello all, There is system. Users are logging , working and logout. Suppose, 5 users are working and Admin wants to find out no. of users working on system with their name ? How to find this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.