Translate

Tuesday 25 March 2014

Session Management

The following are the available Session State Modes in ASP.NET:
  • InProc
  • StateServer
  • SQLServer
  • Custom
  • Off
InProc Session State Mode

The InProc Session State Mode is the default Session State Mode. We can host multiple websites/web applications on a single IIS. Each application runs in a separate Application Domain. The InProc Session State Mode stores session data in a memory object in the application worker process (aspnet_wp.exe) in the application domain. It is usually the fastest, but more session data means more memory is used on the web server, and that can affect performance. 

The session data is stored in the application domain of the web server. When the server restarts then existing data is lost. If you modify the Global.asax file and the Web.Config file for an ASP.NET application then the application will be restarted and all the session data will be lost.

SP.NET provides two events that help you manage user sessions. These events are defined in the Global.asax file of the web application.
Sr. NoEventCall
1Session_Start()This event occurs when a new session begins.
2Session_End()This event occurs when a session is abandoned or expires.

<configuration>
  <
system.web>    
    <
sessionState mode="InProc" timeout="25"></sessionState>
  </
system.web></configuration>

The preceding session timeout setting keeps the session alive for 25 minutes. If you don't define a timeout attribute in the SessionState then the default value is 20 minutes.

Advantages of InProc Session State Mode

Here is a list of the advantages of the InProc Session State Mode.
  1. It is easy to implement.
  2. It stores the session data on the server so it is fast.
  3. In this mode, it is not necessary to serialize and de-serialize to store and retrieve data in the session variables.
Disadvantages of InProc Session State Mode

Here is a list of the disadvantages of the InProc Session State Mode.
  1. When the application domain or worker process recycles, the session data will be lost.
  2. It is usually the fastest, but more session data means more memory is used on the web server, and that can affect performance
  3. It won't work in web farm scenarios and web garden scenarios, because in these scenarios multiple "aspnet_wp.exe" processes will be running on the same machine.
Conclusion
The InProc Session State Mode is a very fast session storing mechanism but suitable only for small web applications. InProc session data would be lost if we restart the server or if the application domain is recycled.
------------------------------------------------------------------------------------------------------


No comments:

Post a Comment