Thursday 15 November 2012

State Server Mode in Session State


State Server Mode in Session State

Introduction

·         Asp.Net provides concept of Sessions. Session means that you can store some data temporarily with asp.net session state and get it back on next server call.
·         In web application development, developers deal with session to access value from multiple pages. Sometime it will be lost session when webserver (IIS) is restarted. We cannot access that variable in application anymore because HTTP protocol is stateless.

      Various Type of Session State Mode

·         Three types of Session State mode available in .Net
o   In Process
§  This is default setting. In this session information will be stored into Webserver.
o   State Server
§  In this mechanism, a Windows service is used to store the session information. It should be noted that there should be only one state server instance running per server farm so that sessions may be shared. State Service is more reliable than in memory because even if one of the web servers goes down (assuming not the one which is executing the state server) the website may still work as the sessions are not lost.
o   SQL Server
§  In this mechanism session is stored in SQL server database.

To Configure Session in Session State Service

·         To use State server mode you ensure that .net framework is installed into computer and to start state service following screen shot.

           Step1:

Go to Computer à Manage à Services à Asp.Net State Service OR
Go to run à Type Service.msc à Start Asp.net State Service

      

 

   Step 2

o   Update web.config file of our application as per following screen shot.
·         For your understanding I made sample code for session state mode and bind grid view. We store data in session from data set. If the IIS restarted then your session variable will not be lost and your application will still be running.

Out Put:

First Output

·         Data will be loaded from the database server on the first call.

IIS restarted Output      

·         Session state preserved even when the webserver (IIS) is restarted.

Conclusion

·         If you don’t specified session mode in your application web.config file then it will automatically takes “In Process Mode” mode.
·         In Process Mode: we cannot preserve session information if Webserver (IIS) is restarted
·         In State Server: we can  preserve session information if Webserver (IIS) is restarted