6.8.08

Session state management in ASP.NET

  • Define Session, SessionId and Session State in ASP.NET.

Answer - A session is the duration of connectivity between a client and a server application. SessionId is used to identify request from the browser. By default, value of SessionId is stored in a cookie. You can configure the application to store SessionId in the URL for a "cookieless" session.

  • What is Session Identifier?

Answer - Session Identifier is used to identify session. It has SessionID property. When a page is requested, browser sends a cookie with a session identifier. This identifier is used by the web server to determine if it belongs to an existing session. If not, a Session ID (120 - bit string) is generated by the web server and sent along with the response.

  • Advantages and disadvantages of using Session State

Advantages of using session state:

It is easy to implement.

It ensures data durability, since session state retains data even if ASP.NET work process restarts as data in Session State is stored in other process space.

It works in the multi-process configuration, thus ensures platform scalability.

Disadvantages of using session state:

Since data in session state is stored in server memory, it is not advisable to use session state when working with large sum of data. Session state variable stays in memory until you destroy it, so too many variables in the memory effect performance.

  • What are the Session State Modes? Define each Session State mode supported by ASP.NET

InProc Mode

This mode stores the session data in the ASP.NET worker process.This is the fastest among all of the storage modes.This mode effects performance if the amount of data to be stored is large.If ASP.NET worker process recycles or application domain restarts, the session state will be lost.

State Server mode

In this mode, the session state is serialized and stored in memory in a separate process.State Server can be maintained on a different system. State Server mode involves overhead since it requires serialization and de-serialization of objects. State Server mode is slower than InProc mode as this stores data in an external process.

SQL Server Mode

In this storage mode, the Session data is serialized and stored in a database table in the SQL Server database. This is reliable and secures storage of a session state. This mode can be used in the web farms. It involves overhead in serialization and de-serialization of the objects.SQL Server is more secure than the InProc or the State server mode.


No comments: