Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - Storing Classes in Session Variables - How it works (memory)?

I've read that you can store classes directly into a session variable i.e.

Session["var"] = myclass;

My question is how the memory management works. Does it automatically serialize this into the session on the client side?

Or does it hold the data for the instance of the class in server memory, and just holds a reference in the session object?

like image 906
Joshua Enfield Avatar asked Mar 31 '11 19:03

Joshua Enfield


2 Answers

ASP.Net will store your object in a static nested dictionary in memory on the server.
It then sends a cookie to the client with the session ID.

Next time the client sends a request, ASP.Net will retrieve the session associated with that ID from the outer dictionary, then give you the inner dictionary containing the objects in that session.

(This is the way the default session provider works; other providers can serialize objects to SQL Server, or do something else entirely)

like image 200
SLaks Avatar answered Sep 28 '22 05:09

SLaks


You don't store classes in the session but instances of these classes. And yes the default session store is memory. You can use SQL Server as session store as well however. Then some serialization will take place.

The session data is not available on client side.

like image 40
ntziolis Avatar answered Sep 28 '22 04:09

ntziolis