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["CurrentUsers"];
            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?
LVL 2
Matt GrofskyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi Michin;

You could use a structure to hold the IP address and the date. See sample code.

      struct UserInfo
      {
            public string IPAddress;
            public DateTime date;
      }
      
      Hashtable App = new Hashtable();
            
      private void button1_Click(object sender, System.EventArgs e)
      {
            UserInfo uInfo = new UserInfo();
            uInfo.IPAddress = "12.56.44.102";
            uInfo.date = DateTime.Now;
            App.Add("CurrentUser", uInfo);
      }


Fernando
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Matt GrofskyAuthor Commented:
Fernando,

Looks like a good option to me, better than me putting in |pipes all over the place

Thanks.
0
Fernando SotoRetiredCommented:
Glad I was able to help. :=)
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Matt GrofskyAuthor Commented:
Fernando,

I forgot to ask, how would I grab the struct out of the hashtable value and parse it?
0
Fernando SotoRetiredCommented:
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
0
Matt GrofskyAuthor Commented:
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"]
0
Fernando SotoRetiredCommented:
What did you call this structure?

     struct UserInfo
     {
          public string IPAddress;
          public DateTime date;
     }

Because the code I sent you works for me.

Fernando
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.