468,107 Members | 1,456 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Application Active users and global.asax

Hi,
Any idea to get the -REAL- number of active users -WITHOUT- this kind of
code ?

----------------------------------------------------------------------------
---------
Sub Session_OnStart
Application.Lock
Application("Active")=Application("Active")+1
Application.Unlock
End Sub

Sub Session_OnEnd
Application.Lock
Application("Active")=Application("Active")-1
Application.Unlock
End Sub
----------------------------------------------------------------------------
---------

This is definitively a wrong way, because some disconnected clients fail to
fire session_onend, which keep the number of active users abnormally high.

I'd like to find something acting like the "current users counter" as seen
in perfmon.
Any help appreciated (really) :)

Thanks in advance,
J.Philippe
Nov 19 '05 #1
5 1839
You can get a third party control to help you, or write a handler. Either
way, the code is going to look similar to what you posted.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------
"Homer J. Simpson" <no*@home.fr> wrote in message
news:d4***********@feed.teaser.net...
Hi,
Any idea to get the -REAL- number of active users -WITHOUT- this kind of
code ?

----------------------------------------------------------------------------
---------
Sub Session_OnStart
Application.Lock
Application("Active")=Application("Active")+1
Application.Unlock
End Sub

Sub Session_OnEnd
Application.Lock
Application("Active")=Application("Active")-1
Application.Unlock
End Sub
----------------------------------------------------------------------------
---------

This is definitively a wrong way, because some disconnected clients fail
to
fire session_onend, which keep the number of active users abnormally high.

I'd like to find something acting like the "current users counter" as seen
in perfmon.
Any help appreciated (really) :)

Thanks in advance,
J.Philippe

Nov 19 '05 #2
Well the code suits what u are looking for..
My advice is just try setting ur session that will suit you in IIS.So
that ur number of active users won't be abnormally high.
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #3
Patrick,

SesionTimout is set to 1Mn in my applications. What else can i tune to track
"dsconnections" ?

Thanks,
J.Ph.

"Patrick Olurotimi Ige" <na********@hotmail.com> a écrit dans le message de
news:ud**************@TK2MSFTNGP12.phx.gbl...
Well the code suits what u are looking for..
My advice is just try setting ur session that will suit you in IIS.So
that ur number of active users won't be abnormally high.
Patrick

*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #4
Homer what do u have set in Web.Config?
Not quiet sure which one overrides but i think Web.Config overrides IIS.
Hope that helps
Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5
Patrick,
Thanks for you patience !

Session.Timeout is now set to 5 Mn in each global.asax.
Here's a sample web.config and global.asax
----------------------------------------------------------------------------
-----
*********** global.asax *************
<%@ Import Namespace="System.Web.mail" %>
<SCRIPT LANGUAGE="VB" RUNAT="Server">

'Exécuté chaque fois qu'un nouvel user se connecte
Sub Session_Start
Dim iiNbActiveUsers As Integer
Dim isGazette As String

iiNbActiveUsers = Application("ApplicationUsers")
iiNbActiveUsers = iiNbActiveUsers + 1
If iiNbActiveUsers <= 0 Then
iiNbActiveUsers = 1
End If
Application.Lock
Application("ApplicationUsers") = iiNbActiveUsers
Application.Unlock

Session.Timeout = 5
End Sub

'Exécuté chaque fois qu'un nouvel user se déconnecte ou part en timeout
Sub Session_End
Dim iiNbActiveUsers as Integer

iiNbActiveUsers = Application("ApplicationUsers")
iiNbActiveUsers = iiNbActiveUsers - 1
If iiNbActiveUsers < 0 then
iiNbActiveUsers = 0
End If

Application.Lock
Application("ApplicationUsers") = iiNbActiveUsers
Application.Unlock
End Sub

'Exécuté à chaque redémarrage de l'application (ou du serveur)
Sub Application_Start
Dim isServerStartDate as String

isServerStartDate = FormatDateTime(Now(),1) & " à " &
FormatDateTime(Now(),4)

Application.Lock
Application("ApplicationStartDate") = isServerStartDate
Application("ApplicationUsers") = 0
Application.Unlock
End Sub

'Exécuté à chaque arrêt de l'application (ou du serveur) sauf en cas de
crash
Sub Application_End
Application.Lock
Application("ApplicationUsers") = 0
Application.Unlock
End Sub

Sub Application_BeginRequest(Sender As Object, E As EventArgs)
End Sub

Sub Application_EndRequest(Sender As Object, E As EventArgs)
End Sub

Sub Application_Error(Sender As Object, E As EventArgs)
Dim isErrorText As String
Dim isUser As String
Dim iiIndex As Integer
Dim ioMailMessage As MailMessage
Dim ioException As Exception

ioException = Server.GetLastError().GetBaseException()

isErrortext = ""
isErrorText = isErrortext & "<b>Serveur :</b> " & Server.MachineName() &
"<br/>"
isErrorText = isErrortext & "<b>Page : </b>" & Request.Path & "<br/>"
isErrorText = isErrortext & "<b>Message :</b> " & ioException.Message &
"<br/>"
isErrorText = isErrortext & "<b>Source :</b> " & ioException.Source &
"<br/>"
isErrorText = isErrortext & "<b>Stack :</b> " & ioException.StackTrace &
"<br/>"

'--------- Gestion des messages SMTP -----------------------
isUser = Request.ServerVariables("AUTH_USER")
iiIndex = Instr(isUser,"\")
If iiIndex <> 0 Then
isUser = Mid(isUser,iiIndex+1)
End If
ioMailMessage = New MailMessage()
ioMailMessage.From = isUser
ioMailMessage.To =
ConfigurationSettings.AppSettings("SiteAdministrat or")
ioMailMessage.Subject = "Erreur sur l'application " & chr(34) &
ConfigurationSettings.AppSettings("SiteName") & chr(34)
ioMailMessage.body = isErrorText
ioMailMessage.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer="SMTPSERVER"
SmtpMail.Send(ioMailMessage)
ioMailMessage = Nothing
'------------------------------------------------------------

'On force un GC.Collect()
GC.Collect()
End Sub
</SCRIPT>

*********** web.config *************
<?xml version="1.0" encoding="windows-1252"?>
<configuration>
<appSettings>
<add key="SiteName" value="Comite du medicament et des dispositifs
medicaux steriles"/>
<add key="SiteAdministrator" value="webmaster@intranet" />
<add key="ActiveSite" value="1"/>
<add key="SiteRoot" value="/COMEDIMS"/>
<add key="SiteDatabase" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\InetPub\WWWRoot\COMEDIMS\_database\site. mdb;"/>
<add key="UserDatabase" value=""/>
<add key="CookieName" value="COMEDIMS :: Preferences"/>
<add key="CurrentMessage" value="15-10-2003"/>
</appSettings>
<system.web>
<authentication mode="Windows"/>
<authorization>
<allow users="*"/>
</authorization>
<customErrors mode="Off"/>
<compilation debug="true">
<assemblies>
<add
assembly="System.DirectoryServices,Version=1.0.330 0.0,Culture=neutral,Public
KeyToken=b03f5f7f11d50a3a"/>
</assemblies>
</compilation>
</system.web>
</configuration>
----------------------------------------------------------------------------
-----

I still can't figure why, even after setting timeout to 5 mn, session_onend
is not fired.
This keeps [Application("ApplicationUsers")] abnormally high. Any idea why ?

Thanks in davance,
J.Philippe
Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mike Owen | last post: by
5 posts views Thread by John Christensen | last post: by
5 posts views Thread by Leon | last post: by
6 posts views Thread by jim | last post: by
16 posts views Thread by Fernando Arámburu | last post: by
8 posts views Thread by Vishwanathan Raman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.