Friday, September 28, 2012

Complete Details about session state management in Asp.net

Title:State management in asp.net

Description And Explanation:
The session setting provide following options:
1.Session mode
2.cookie less session
3.session timeout
4.optimisation of session
session mode:
It will specify when the session to be maintained.Asp.net is providing different types of session modes
1.State server session
2.SQL server session
3.In process session[default]
4.Custom session[Requires manual coding]
In process session[Process dependent session]:
session maintained with in website app domain under works process is called "In process session" or process dependent session.This produce come with two problems
1.No reliability:Restoring website with erase sessions[saving web.config or restarting web server will restart website]
2.No solution for web forming
Web forming:It is running different websites on different web services as a one unit,This is implemented for load balancing
In web forming single session can not be maintained fore client
Process Independent session
In session maintained outside of website external to under process calls process independent".the external process to maintain session can be
1.State server
2.Sql server
Database server session:
This requires following steps
* start state server:State server comes with .net installation in the form of windows service
start --->run-->services.msc
then select asp.net state server --->right click and select start--->state server will be started to maintain
Configure website to state server for maintaining session
Go to application web.config file
<system.web>
<session state mode="state server" state connection string="tcp/ip= 127.0.0.1:2424">
</system.web>

Note:state connection string requires IP address of system in which state server is running and port number of state server
TcpIp=Ipadress:port number
Note:State server will support in memory storage,data will be lost will state server is restarted and backup can not be maintained.When reg is move reliability go with sql server

Sql server session:
Sql server supports persistent storage in the form of table,This provide mode reliability with more financial investment and requires more processing
This requires following steps
*continue sqlserver with table to maintain session
.net is providing asp.net -regsql.exe utility
VS2010 command prompt-->asp.net -regsql -u "sa" -p "" -ssadd -sstype "c" -d "test"
It will place table into sql server
Configure website to maintain session with sql server
<system.web>
<session state mode="SQLserver"  sqlconnection string="user=sa;password="" database="test" allow customDatabse="true">
</system.web>

Note:Sql server agent will maintain Job to monitor session when timeout occurs  it will delete sessions
Cookie less session:
By default session ID wll be given to browser in the form of in memory Cookie,if the browser disabled cookies session can not be maintained
The solution is cookieless session providing session Id to client Browser by appending to URL is called cookies less session.
<sessionstate cookieless="usecookies
                                         useurl
                                        useDeviceProfile
                                        autoDetect
                                        true
                                        false" time out=""
</session state>
Use Cookies:will provide session id in the form of cookies
Use URL will provide session Id by
Use Device Profile:Session will be given based on requested device in the form cookies
Auto Detect:It is similar to use device profile.It will verify device browser enabled cookies
True:It is similar to use URL
False:It is similar to use cookies

No comments:

Bel