Types of session

Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Three Types of Session

i) inprocess session  (also know as IN Process session)
II)out Process session

Out Proc is further of two type:

2.)stateserver

3.)SQl-server session

IV)Cookieless session

1.) Inprocess session by default in web.cofig File.

In this mode session state is stored in a current process and when this process terminates then also the data saved in session state will be lost. This mode is set by default in ASP.NET, underneath you can see example of configuring such a state in web.config file:

Code:
<configuration> <sessionstate mode=”inproc” cookieless=”false” timeout=”30″ sqlconnectionstring=”data source=127.0.0.1;user id=user;password=pass” server=”127.0.0.1″ port=”42424″ />
</configuration>

The most important parameters of this session state are the following:

  • mode – there can be three values of this parameters – inproc, sqlserver, stateserver. Value inproc in our example indicates that session state is in in-process mode
  • cookieless – boolean value of this parameters indicates if cookies are needed for session state to work
  • timeout – indicates a time for how long a session is valid. Each time when user interacts with your application the timeout is set to current time plus value of the timeout

2.) Stateserver.

In this mode session is stored in separate process so other processes can be terminated and session state will be still maintained. This is a sample configuration of session state in web.config for out-of-process mode:

Code:

<configuration> <sessionstate mode=”stateserver” cookieless=”false” timeout=”30″ sqlconnectionstring=”data source=127.0.0.1;user id=user;password=pass” server=”127.0.0.1″ port=”42424″ />
</configuration>

Underneath you can see parameters for session state in out-of-process mode:

  • mode value set for stateserver indicates that it works in out-of-process mode
  • service – indicates a server where state service is, in this example it’s a localhost
  • port – indicates a port of state service

3.) sql-server session is stored in Database(sql).

In SQL server mode session state is stored in SQL server. To configure it you have to put the following code in web.config file:

Code:

<configuration> <sessionstate mode=”stateserver” cookieless=”true” timeout=”30″ sqlconnectionstring=”data source=127.0.0.1;user id=user;password=pass” server=”127.0.0.1″ port=”42424″ />
</configuration>

4.)CookieLess Session

In this mode cookies in client’s browser are not required to be enabled. This mode works by modifying URL address with id that identifies the session. The configuration is the following:

<configuration> <sessionstate mode=”stateserver” cookieless=”true” timeout=”30″ sqlconnectionstring=”data source=127.0.0.1;user id=user;password=pass” server=”127.0.0.1″ port=”42424″ />
</configuration>
Parameter that is vital for this mode is “cookieless” – set in our example to true, which means that cookies are not needed to maintain the state. You already know what is the advantage of this solution – it doesn’t require cookies.


Share the joy
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.