Application Active users and global.asax

H

Homer J. Simpson

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
 
A

Alvin Bruney [Microsoft MVP]

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
 
P

Patrick Olurotimi Ige

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
 
H

Homer J. Simpson

Patrick,

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

Thanks,
J.Ph.
 
P

Patrick Olurotimi Ige

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
 
H

Homer J. Simpson

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("SiteAdministrator")
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.3300.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top