Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is really stored in Session in ASP.NET?

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?

like image 451
juan Avatar asked Dec 02 '08 19:12

juan


People also ask

What data is stored in session?

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.

What session contains?

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.

What is the mode of storing ASP.NET session?

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.

Is session data stored on the client or the server?

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.


1 Answers

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

like image 86
Gargi Avatar answered Sep 21 '22 18:09

Gargi