Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Wednesday, August 4, 2010

Session object in asp.net

Session object:

Session object is used to store state specific information per client basis. It is specific to particular user.
Session data persists for the duration of user session you can store session's data on web server in different ways.
Session state can be configured using the section in the application's web.config file.

Session state in ASP.NET can be configured in different ways based on various parameters including scalability, maintainability and availability

1.In process mode (in-memory)- State information is stored in memory of web server
2.Out-of-process mode- session state is held in a process called aspnet_state.exe that runs as a windows service.
3.Database mode – session state is maintained on a SQL Server database.

In process mode:
This mode is useful for small applications which can be hosted on a single server. This model is most common and default method to store session specific information. Session data is stored in memory of local web server

Configuration information:



Advantages:
Fastest mode
Simple configuration

Disadvantages:
Session data will be lost if the worker process or application domain recycles
Not ideal for web gardens and web farms

Out-of-process Session mode (state server mode):

This mode is ideal for scalable and highly available applications. Session state is held in a process called aspnet_state.exe that runs as a windows service
which listens on TCP port 42424 by default. You can invoke state service using services MMC snap-in or by running following net command from command line.

Net start aspnet_state

Configuration information:



Advantages:
Supports web farm and web garden configuration
Session data is persisted across application domain recycles. This is achieved by using separate worker process for maintaining state
Disadvantages:
Out-of-process mode provides slower access compared to In process
Requires serializing data

SQL-Backed Session state:
ASP.NET sessions can also be stored in a SQL Server database. Storing sessions in SQL Server offers resilience that can serve sessions to a large web farm that
persists across IIS restarts.
SQL based Session state is configured with aspnet_regsql.exe. This utility is located in .NET Framework's installed directory
C:\\microsoft.net\framework\. Running this utility will create a database which will manage the session state.

Configuration Information:


Advantages:
Supports web farm and web garden configuration
Session state is persisted across application domain recycles and even IIS restarts when session is maintained on different server.

Disadvantages:
Requires serialization of objects



Mode:
This setting supports three options. They are InProc, SQLServer, and State Server

Cookie less:
This setting takes a Boolean value of either true or false to indicate whether the Session is a cookie less one.

Timeout:
This indicates the Session timeout vale in minutes. This is the duration for which a user's session is active. Note that the session timeout is a sliding value;
Default session timeout value is 20 minutes

SqlConnectionString:
This identifies the database connection string that names the database used for mode SQLServer.

Server:
In the out-of-process mode State Server, it names the server that is running the required Windows NT service: aspnet_state.

Port:
This identifies the port number that corresponds to the server setting for mode State Server. Note that a port is an unsigned integer that uniquely identifies
a process running over a network.

You can disable session for a page using EnableSessionState attribute. You can set off session for entire application by setting mode=off in web.config file
to reduce overhead for the entire application.

Thanks & Regards
Santosh Singh

No comments:

Post a Comment