i will start with a singleton snippet right now.. if you need any further
help you know what to do
using System;
using System.Collecti ons;
public class CUserInfo
{
private string sessionID;
private DataTime sessionTimeStam p;
public CUserInfo(strin g Sessionid, DateTime SessionTS)
{
sessionID = SessionID;
sessionTimeStam p = SessionTS;
}
public string SessionID
{
get
{
return sessionID;
}
set
{
sessionID = value;
}
}
public DateTime SessionTimeStam p
{
get
{
return sessionTimeStam p;
}
set
{
sessionTimeStam p = 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 CSessionManange r();
}
return _csmInstance;
}
public Static void AddUserInfo(CUs erInfo cui)
{
// do your checks here. like is the info already present ?
_alContainer.Ad d(cui)
}
public static CUserInfo CurrentUserInfo
{
get
{
string sessionID = this.context.Se ssion.SessionID ;
foreach(CUserIn fo csi in _alContainer)
{
if(csi.SessionT imeStamp == sessionID)
{
return csi;
break;
}
}
}
set
{
// find the item & update it or remove the item if found
_alContainer.Ad d(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 myCurrentInstan ce = 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(O bject sender, EventArgs e)
{
CUserInfo csi = new CUserInfo(this. context.Session .SessionID,
DateTime.Now()) ;
CSessionManager csmanager = CSessionManager .GetInstance();
csmanager.AddUs erInfo(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******** ******@TK2MSFTN GP15.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******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP10.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