0

複数のセッション値を保存する最善の方法について、いくつかの混乱があります。私の友人の 1 人は、HashTable で定義するよりも、セッションを 3 ~ 4 回定義する方が重いと言いました。以下のシナリオのように:問題は、どちらが優れているか、そしてその理由です。

        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; 

どんな提案も本当に感謝しています!

上のシナリオで、私の TL は、ハッシュテーブルが 1 つずつ (3MB かかると仮定) ではなく、サーバー上で少量のメモリ (500 kb かかると仮定) を必要とすることを教えてくれました。

4

2 に答える 2

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.

于 2013-04-04T06:33:13.960 に答える
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

于 2013-04-04T06:36:12.677 に答える