We are trying to decide how to handle object persistence accross postbacks, to avoid getting the data from the database in every request, and I'm leaning towards using Session (it's an intranet application, there won't be thousands of users), but this is due to the fact that I suspect that only the reference to the real object is stored there...
Does anyone know for a fact if this is true?
I've always been taught not to over use the session object, but if it works this way it wouldn't really be a big problem...
What is really stored in session here:
Session["myKey"] = myObject;
The actual serialized object, or its reference?
Session storage is a popular choice when it comes to storing data on a browser. It enables developers to save and retrieve different values. Unlike local storage, session storage only keeps data for a particular session. The data is cleared once the user closes the browser window.
Sessions are server-side files that contain user information, whereas Cookies are client-side files that contain user information. Session is dependent on Cookie, but Cookie is not dependent on a session. Session ends when a user closes his/her browser, while a Cookie expires depending on the lifetime you set for it.
InProc mode, which stores session state in memory on the Web server. This is the default. StateServer mode, which stores session state in a separate process called the ASP.NET state service.
Session information is stored on the server and passed between pages. ASP.NET session ID: When a user first opens their Web browser and then goes to a website that implements ASP.NET session state, a cookie is sent to the browser with the name "ASP. NET_SessionId" and a 20-character value.
I have tried this:
I have created a class and store an instance of this in session (session state mode: InProc). Instance lives in aspnet_wp.exe proc.
Then, I changed session state to SQL Server (still without [Serializable] attribute) and I got the following error.
Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted.
So, there is no serialization for inProc session state.
Cheers... Martín
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With