473,614 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting Sessions

kpg
Hi all,

Ah yes, the age old counting session question.

sessionstate
mode="InProc"
timeout="5"

Sub Application_Sta rt()
Application("Co ncurrentUsers") = 0
End Sub

Sub Session_Start()
Application.Loc k()
Application("Co ncurrentUsers") += 1
Application.UnL ock()
End Sub

Sub Session_End()
Application.Loc k()
Application("Co ncurrentUsers") = -= 1
Application.UnL ock()
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("Co ncurrentUsers")
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 2179
Take a look at the System.Diagnost ics 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_Sta rt()
Application("Co ncurrentUsers") = 0
End Sub

Sub Session_Start()
Application.Loc k()
Application("Co ncurrentUsers") += 1
Application.UnL ock()
End Sub

Sub Session_End()
Application.Loc k()
Application("Co ncurrentUsers") = -= 1
Application.UnL ock()
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("Co ncurrentUsers")
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?RGF2aWQgSmV zc2Vl?= once said in
microsoft.publi c.dotnet.framew ork.aspnet
Take a look at the System.Diagnost ics 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.Diagnost ics.Performance Counter( _
"ASP.NET Applications",
"Sessions Active",
"_LM_w3svc_1_ro ot_LSFB1")

lblUsers.Text = objCounter.RawV alue.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.Sess ionState.HttpSe ssionStateConta iner 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?RGF2aWQgSmV zc2Vl?= once said in
microsoft.publi c.dotnet.framew ork.aspnet
Take a look at the System.Diagnost ics 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.Diagnost ics.Performance Counter( _
"ASP.NET Applications",
"Sessions Active",
"_LM_w3svc_1_ro ot_LSFB1")

lblUsers.Text = objCounter.RawV alue.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?RGF2aWQgSmV zc2Vl?= once said in
microsoft.publi c.dotnet.framew ork.aspnet
I decompiles the System.Web.Sess ionState.HttpSe ssionStateConta iner 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.timeou t = 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
3120
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 session id variable is checked for. if noe exist, a piece of code will create on. then the session id is store in a table under one column and the pages pre-defined number will be stored under another. so if i want to check how many users have access...
3
3137
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 value does not increase. I would appreciate some guidance. Thank you
1
1670
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 at-least count the customers or visitors in my "Store" (only in store), users of the other sections should not be counted. Whenever a user in my store signs out or closes the
8
1638
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 like this - I need that the script will accurate as possible). On the server side I have the .NET server. Thanks :)
3
3225
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 7 2004 10:57 am Subject: Have trouble with reference counts! Reply | Reply to Author | Forward | Print | Individual Message | Show original | Remove | Report Abuse
2
1413
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. Unfortunately, Can't find a way to check this in ASP.NET. Looked at performanceCounters but have not had any success there. Anyone got any ideas?
3
28221
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 developer needs to know how to use. This article explains the basics of PHP Sessions. Assumptions: Basic PHP knowledge is required (variables, arrays and such) HTML Forms. What are Sessions? Sessions are a way of storing data. When developing...
8
3736
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 bool field to the table and set each user to 1 if they are logged in, and 0 if they are not logged in? *** Sent via Developersdex http://www.developersdex.com ***
2
1543
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 ? Thanks in advance.
0
8182
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8130
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8279
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7093
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6088
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5540
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.