tags:

views:

603

answers:

4

Coming from an Classic ASP background I'm pretty cautious about placing objects into Session.

Would it be a bad idea for me to store an object of type Dictionary into Session within .NET?

A: 

You can put anything into Session... You just have to make sure not too much data is put into Session as this takes up server resources. This is something that will not be visible when testing your site at first, only when you deploy it and a lot of users start using it, as every user has its own Session object on the server.

fretje
+3  A: 

Well, you won't have some of the issues that you would have with ASP. .net is not STA COM, so the thread affinity problems that you had with ASP are not going to hurt you (unless you try to store an STA COM object in the session, or in your dictionary).

Do be careful about concurrent access, though. If it is possible that multiple threads could access the dictionary (do to asynchronous page code, or maybe AJAX calls), then you will need to apply appropriate locking to the dictionary.

JMarsch
Excellent thats what I wanted to hear :-) The threading issues were my main concern, the actual size of the objects being stored in Session will be tiny due to them being rarely used only by admins.
Craig Bovis
A: 

The big picture issues aren't really different than classic ASP (though I confess I didn't think about the differences that JMarsch raised). The answer depends on numerous factors:

  • How many concurrent sessions you expect (and how many you intend to support)
  • The size of the Dictionary
  • Your server(s)'s memory characteristics
  • Everything else your server(s) need to do
Jeff Sternal
@Jeff: There is an imprtant difference. With classic ASP, your objects were usually STA COM objects, and you can get into trouble putting those into the session and accessing them on subesquent postbacks. Your .Net objects are not STA COM (unless you explicitly make them so), so they are not subject to the same issues.
JMarsch
Ack, I updated my answer to point to yours. I'm tempted to my this lame generalization of an answer but I think I'll just leave it here as a reminder to myself.
Jeff Sternal
Been there too ;)
JMarsch
+1  A: 

Well, it depends on what you want to achieve, for simple things like persisting state between page postbacks, I recommend you to use the ViewState.

CMS