i will start with a singleton snippet right now.. if you need any further
help you know what to do
using System;
using System.Collections;
public class CUserInfo
{
private string sessionID;
private DataTime sessionTimeStamp;
public CUserInfo(string Sessionid, DateTime SessionTS)
{
sessionID = SessionID;
sessionTimeStamp = SessionTS;
}
public string SessionID
{
get
{
return sessionID;
}
set
{
sessionID = value;
}
}
public DateTime SessionTimeStamp
{
get
{
return sessionTimeStamp;
}
set
{
sessionTimeStamp = value;
}
}
}
public class CSessionManager
{
private static CSessionManager _csmInstance = null;
private ArrayList _alContainer;
private CSessionManager()
{
_alContainer = new ArrayList();
}
public Static CSessionManager GetInstance()
{
if(_csmInstance == null)
{
_csmInstance = new CSessionMananger();
}
return _csmInstance;
}
public Static void AddUserInfo(CUserInfo cui)
{
// do your checks here. like is the info already present ?
_alContainer.Add(cui)
}
public static CUserInfo CurrentUserInfo
{
get
{
string sessionID = this.context.Session.SessionID;
foreach(CUserInfo csi in _alContainer)
{
if(csi.SessionTimeStamp == sessionID)
{
return csi;
break;
}
}
}
set
{
// find the item & update it or remove the item if found
_alContainer.Add(value);
}
}
// Add your public static methods that you wish to call
// say for example to query the SessionManager for count etc
}
Once you create this object you should have the access to same instance
every time you call
CSessionManager myCurrentInstance = CSessionManager.GetInstance();
note that with singleton to get an instance you call the static GetIstance
method and you do not use the new keyword.
Place it in your cache or application object and you should have access
everywhere.
now to add the user
use Global.asax and use the methof Session_Start
here you have access to context object to use it to get session ID
protected void Session_Start(Object sender, EventArgs e)
{
CUserInfo csi = new CUserInfo(this.context.Session.SessionID,
DateTime.Now());
CSessionManager csmanager = CSessionManager.GetInstance();
csmanager.AddUserInfo(csi);
// you should be able to get sessionID (though i never needed to use
session id in this way so am not 100%)
}
--
Regards,
Hermit Dave
(
http://hdave.blogspot.com)
"Christina N" <no@mail.com> wrote in message
news:OT**************@TK2MSFTNGP15.phx.gbl...
Yes, but HOW do I do that? I need a code example.
Can you help me?
Christina
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:OR**************@tk2msftngp13.phx.gbl... Christina,
what you need to do is create a Singleton which has a internal
collection or an arraylist.
on session start. look up the user info you require and populate the
arraylist.
--
Regards,
Hermit Dave
(http://hdave.blogspot.com)
"Christina N" <no@mail.please> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl... Can anyone give me a code example of how to use a global array to keep
track
of
all active sessions (their sessionid, logontime, etc)?
I need a code example, not a prosa description of what to do..
Anyone..?
Best regards,
Christina