[ASP] Lister les SessionID en cours

cs_bugzilla79 Messages postés 9 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 20 mai 2005 - 20 janv. 2003 à 11:40
cs_bugzilla79 Messages postés 9 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 20 mai 2005 - 20 mai 2005 à 15:23
bonjour @ tous, je cherche le moyen de lister tous les session.sessionID en cours sur mon site.
qq'un connait le moyen de faire ça ?

merci !

6 réponses

cs_fabrice69 Messages postés 1765 Date d'inscription jeudi 12 octobre 2000 Statut Membre Dernière intervention 11 décembre 2013 5
20 janv. 2003 à 20:32
0
shaiulud Messages postés 404 Date d'inscription mardi 18 décembre 2001 Statut Membre Dernière intervention 15 juillet 2014 22
21 janv. 2003 à 11:25
<%'global.asa%>
<OBJECT RUNAT= Server
SCOPE=Application
ID=ListSession
PROGID="Scripting.Dictionary">
</OBJECT>

<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Session_OnStart
Application.Lock()
Application("NB_USERS")= CLng(Application("NB_USERS")) +1
Application.StaticObjects.Item("ListSession").Add Cstr(Session.SessionId), Cstr(Session.SessionId)
Application.UnLock()
End Sub

Sub Session_OnEnd
Application.Lock()
if Application("NB_USERS")>0 then
Application("NB_USERS")= CLng(Application("NB_USERS")) - 1
else
Application("NB_USERS")=0
end if
Application.StaticObjects.Item("ListSession").Remove(CStr(Session.SessionId))
Application.UnLock()
End Sub

</SCRIPT>

<%'default.asp%>
<%

Sub ListSessionID
Dim arUserNames, arUserIDs, i, userName
arUserIDs = Application.StaticObjects.Item("ListSession").Keys
arUserNames = Application.StaticObjects.Item("ListSession").Items
For i = 0 To Application.StaticObjects.Item("ListSession").Count-1
If (Session.SessionID = arUserIDs(i)) Then
userName = " " & arUserNames(i) & " "
Else
userName = arUserNames(i)
End If

Response.Write "<tr><td>"& userName &"</td></tr>"
Next
End Sub

response.write "Session en Cours :"& Session.SessionID
%>

Liste des Sessions :

<%ListSessionID%>
0
cs_bugzilla79 Messages postés 9 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 20 mai 2005
23 janv. 2003 à 10:48
merci !

mais y'a pas un moyen de faire autrement qu'avec le global.asa ? j'ai l'impression que ça déconne chez moi, la dernière fois que j'ai testé, ça ne fonctionnais absolument pas (j'avais testé un script d'un tutorial).
0
shaiulud Messages postés 404 Date d'inscription mardi 18 décembre 2001 Statut Membre Dernière intervention 15 juillet 2014 22
24 janv. 2003 à 21:26
Malheureusement, il n'y a pas d'autre solution,
il n'existe pas de méthode directe pour lister l'ensemble des session en cours.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_bugzilla79 Messages postés 9 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 20 mai 2005
20 mai 2005 à 11:43
Bon, je reviens un peu vers ce topic. Je m'étais un peu inspiré de vos conseils pour pondre ce code. Au vu du code de Shaiulud, j'ai tenté d'accéder au Session.SessionID dans la Sub Session_OnEnd.
Manque de pot, on dirait qu'à la fin de la session, le SessionID n'est plus dispo. C'est une impression ou pas ?!
Pour rappel et pour illustrer mes propos, le code de Shaiulud dit :

Application.StaticObjects.Item("ListSession").Remove(CStr(Session.SessionId))
Ce qui sous-entend que le SessionID est tjs dispo dans Session_OnEnd.

Voici mon fameux code compris dans mon global.asa :
<script language="VBScript" runat="Server">
Sub Session_OnEnd
Application.Lock()
'---------- Vidage du panier
Set connVidePanier = CreateObject("ADODB.Connection")
connVidePanier.Open [ma chaine de connexion à la base de données]
connVidePanier.Execute("Delete * From Panier Where Pan_Session = '" & Session.SessionID & "'")
connVidePanier.Close
Set connVidePanier = Nothing

Application.UnLock()
End Sub
</script>
0
cs_bugzilla79 Messages postés 9 Date d'inscription lundi 20 janvier 2003 Statut Membre Dernière intervention 20 mai 2005
20 mai 2005 à 15:23
Article du site asp101.com

http://www.asp101.com/tips/index.asp?id=79

en gros, ça explique pourquoi les événements sur Session_OnEnd et sur
Application_OnEnd, ça marche mal ou du moins pourquoi on peut pas
récupérer de messages d'erreur... Super !!!






Quick Tips

<hr color="#0000ff" size="3">
Global.asa OnEnd Events Don't Run

<hr>



I continually get questions concerning the Application_OnEnd
and Session_OnEnd event handlers in global.asa not running.
The problem is usually not that the server isn't set up right
or that it's broken. It's usually something much simpler.

What developers tend to forget that the OnEnd events have no
way to tell you when something's wrong. This is understandable
since all the other pages on a web site and even the
Application_OnStart and Session_OnStart don't have this problem.
It stems from the fact that the OnEnd events execute long
after the user has
left so there's no browser to send an error message to.
As a result, you might never know there's a problem with your
code and the smallest bug or typo can cause the whole
routine to not execute at all.

Because of this, you really need to be extra careful when writing
or modifying code for these particular subroutines. I
recommend adding a set of code with noticable results at the
end of the routine during testing. For live code, some decent
error handling will help catch those run time errors that
seem to "just happen" on their own.
0
Rejoignez-nous