0

I have some confusion over best way to store multiple session values. One of my friend told us that define session 3-4 times is heavy rather then define in a HashTable. Like below scenario : The question is which is better one & why.

        Hashtable ht = new Hashtable();
        ht.Add("UserID", txtUser.Text);
        ht.Add("Type", type.Text);
        ht.Add("PaypalID", paypal.Text);
        Session["hashtab"] = ht;          //-- Is this better way or below one.

        Session["UserID"] = txtUser.Text;
        Session["Type"] = type.Text; 
        Session["PaypalID"] = paypal.Text; 

Any Suggestions really appreciate !

Please light over that in upper scenario my TL told me that hashtable takes minor memory on the server (suppose it takes 500 kb) rather than one by one (suppose it takes 3MB).

Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
John
  • 697
  • 4
  • 13
  • 27

2 Answers2

1

I'd use the second style.

This is highly unlikely to be an area which affects the performance of your application.

If your session state is held in process, any savings are likely to be negligible.

If your session state is held in state server or SQL Server, the IPC overheads and serialization costs are likely to swamp any micro-optimization like this.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
0

The second style is preferred generally, check this: http://msdn.microsoft.com/en-us/library/ms178581%28v=vs.100%29.aspx

On a different note, you could check this out as well: ASP.NET: Multiple Session objects in a single application

Community
  • 1
  • 1