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


No comments:

Post a Comment