Matt Grofsky
asked on
Hashtable Storing Users, but I have more than 2 things I need to store.
I'm currently doing something along the lines of
public Hashtable MyAppUsers
{
get
{
Hashtable a = (Hashtable)Application["Cu rrentUsers "];
if (a == null)
{
a = new Hashtable(2);
Application.Lock();
Application["CurrentUsers" ] = a;
Application.UnLock();
}
return a;
}
}
To store users in a C# website. Basically just doing a MyAppUsers.Add(key,data) and so on.
The key is the user login and the data is a date for the last time the hashtable entry was updated. I'm trying to figure out how I could also add an IP address in there as sometimes I have multiple people using the same login but not always fromt he same IP.
The only thing I can thing of off the top of my head is to make the key,value pair something like MyAppUsers(Login|IPAddress ,Data) where Login|IPAddress is the key and the date is the value.
I would ideally want to have something like
JohnK,1.2.3.4,4/10/2006
JohnK,2.4.2.3,5/10/2005
Marryj,6.5.4.3,3/1/2006
and so on... with 3 values across but have no idea how to do it except for putting some delimiter in the Key and then parsing the key to get two values.
Any ideas?
public Hashtable MyAppUsers
{
get
{
Hashtable a = (Hashtable)Application["Cu
if (a == null)
{
a = new Hashtable(2);
Application.Lock();
Application["CurrentUsers"
Application.UnLock();
}
return a;
}
}
To store users in a C# website. Basically just doing a MyAppUsers.Add(key,data) and so on.
The key is the user login and the data is a date for the last time the hashtable entry was updated. I'm trying to figure out how I could also add an IP address in there as sometimes I have multiple people using the same login but not always fromt he same IP.
The only thing I can thing of off the top of my head is to make the key,value pair something like MyAppUsers(Login|IPAddress
I would ideally want to have something like
JohnK,1.2.3.4,4/10/2006
JohnK,2.4.2.3,5/10/2005
Marryj,6.5.4.3,3/1/2006
and so on... with 3 values across but have no idea how to do it except for putting some delimiter in the Key and then parsing the key to get two values.
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I was able to help. :=)
ASKER
Fernando,
I forgot to ask, how would I grab the struct out of the hashtable value and parse it?
I forgot to ask, how would I grab the struct out of the hashtable value and parse it?
Hi Michin;
The following code will get the current user info from the Hashtable and cast that object to a UserInfo object and then displays the information in that structure.
UserInfo uInfo = (UserInfo) App["CurrentUser"];
MessageBox.Show("IPAddress = " + uInfo.IPAddress + " Date = " +
uInfo.date.ToString());
Fernando
The following code will get the current user info from the Hashtable and cast that object to a UserInfo object and then displays the information in that structure.
UserInfo uInfo = (UserInfo) App["CurrentUser"];
MessageBox.Show("IPAddress
uInfo.date.ToString());
Fernando
ASKER
Fernando,
Hmm ya I tried that also but I get a Inalid Cast Exception...Specified cast is not valid when I try to cast the (UserInfo)App["CurrentUser "]
Hmm ya I tried that also but I get a Inalid Cast Exception...Specified cast is not valid when I try to cast the (UserInfo)App["CurrentUser
What did you call this structure?
struct UserInfo
{
public string IPAddress;
public DateTime date;
}
Because the code I sent you works for me.
Fernando
struct UserInfo
{
public string IPAddress;
public DateTime date;
}
Because the code I sent you works for me.
Fernando
ASKER
Looks like a good option to me, better than me putting in |pipes all over the place
Thanks.