1

Possible Duplicate:
ASP.NET Session size limitation

I am building a asp.net c# webforms application. I want to know whats best wrapper class do you use for session handling? And how much data can we store in session? What's limit?

Community
  • 1
  • 1
Riz
  • 6,746
  • 16
  • 67
  • 89

2 Answers2

2

You may want to check out this post-

ASP.NET Session size limitation

As for the wrapper class, there really isn't a lot you need to do. I usually find it best to have only one class accessing the session. I usually use a static property to retrieve the objects I want.

public static class MyData
{
    public static MyObject Item1 { 
        get { return HttpContext.Current.Session["DataKey"] as MyObject;}
        set { HttpContext.Current.Session["DataKey"] = value;}
    }
}

Obviously you can modify the pattern as needed to auto construct the objects.

Community
  • 1
  • 1
Kelly Robins
  • 7,168
  • 6
  • 43
  • 66
2

Be very careful with storing a lot of data in session. remember, session lasts as long as the person's "session" is active. you might have a server that can do 200 requests a second, but you may have 15,000 people who you are maintaining session for at the same time. Assuming you are using the default for session (which is server memory), you may quickly find your server running out of memory.

It sounds odd, but for scalability, look hard at storing stuff in cookies, and or your db.

Peter Kellner
  • 14,748
  • 25
  • 102
  • 188
  • 1
    Thanks for your answer peter. But we have a website that will have lot of permission settings and I want to store those in session when user logs in. More Permissions can be added too in future. Other way can be to get permission from db every time user refreshes the page, but I don't want to get 50+ rows every time user refreshes page. What u suggest in this case? – Riz Jul 16 '11 at 11:39
  • 1
    You should keep cookies as lean as possible, all you're doing is pushing the problem somewhere else. A DB or out of process state manager is a better option. – Kev Jul 16 '11 at 16:57
  • 1
    I totally understand why you want to use session and you may not have any other choice. If you do use session, make sure you have tested it at scale. there are several choices that are much faster than using the database session provider. There are several thirdparty solution as well as microsoft session state server (velocity, renamed app fabric I think). (as Kev says, keep your cookies mean and lean. If you can cram your role defs in a tiny space, that works, otherwise, you do have to have a server side solution). Just make sure you pick something that is webfarm safe. – Peter Kellner Jul 17 '11 at 23:02