Limitations of Storing the session data within web server as an In-Process data:-
1.Inspite the site is maintained in more than one webserver if the session data is stored as an InProcess data within webserver and if that server crashes then the other webserver cant read the session data and hence the response will not be provided to the client.
2. No Reliability:- Sessions will be lost when appdomain is recycled[saving web.config or restarting webserver will recycle appdomain]
To check :- open a website using sessions , execute it, now save changes on web.config while website is running ,now access the session data it will raise error because session expires due to saving changes in web.config file.
3. No Solution for Web Farming:- Web Farming is the concept of running different websites on default webservers as a one unit, this is implemented as a part of load balancing.
Browser ---------------------------------- | webserver
| ------- website1----session
|
|---- Webserver----session[new]
Website2
The single session cant be maintained for client within webfarming towards process dependent session.
Solution from ASP.NET:- ASP.NET supports to store the data as an Out-Process information[Process Independent Session]. The session outside the appdomain external to worker process is called “Process independent session”
Maintaining the session information as an Out-Process data:
ASP.NET can store the data within SqlServer or StateServer.
Storing Session data within State Server:- state server comes with .net installation as a service of o/s , it should be started to maintain sessions.
1. Start the ASP.Net State Service(windows service):
Start --- Run --- Services.msc
|
Services ------Name
|
ASP.NET State Service – rt click and Start
2. Configure ASP.NET website for maintaining the session information within state Server:-
<System.Web>
<SessionState Mode=”StateServer” StateConnectionString=”tcpip=127.0.0.1:42424” />
[ip address of system in which state server is running and port number of state server[42424]]
Now go to web.config and save it , website will be recycled, session will not be effected.
Note:- state server supports In-memory storage, when the system is restarted or system crash occurs sessions will be lost, backup cant be maintained.
Solution is maintaing data in SqlServer.
Storing the session information within sqlserver database:-sqlserver supports persistent storage in the form of table representation, this provides more reliability with more financial investment.
1. Start the SqlServerAgent service: sqlserver should remove session when timeout occurs, this work will be done by sqlserver agent.
Start --- Run --- Services.msc
|
Services ------Name
|
SqlServerAgent – rt click and Start
2. Configuring SqlServer with table to maintain sessions:
Create the database and the tables needed for storing a session information within the SqlServer database, this can be achieved in two ways:-
a)
Start --- Run --- isqlw[2000]/sqlwb[2005]
|
SqlSever Management Studio
Now goto File – Open – c:\windows\microsoft.net\framework\V 2.0.0.50727\InstallSqlState[open it]
Now press F5 à executing procedure
Aspstatetempsessions table will be created in tempdb by default.
To verify :-
In Sqlserver : Use tempdb
Select * from aspstatetempsessions
b) Dotnet is providing aspnet_regsql.exe utility:
Aspnet_regsql –U “sa” –P “nishi” –ssadd –sstype “t|p|c” –d “database”
ssadd: it will specify adding table for session
sstype:
sstype:
t: table will be placed into tempdb database, when sqlserver is stopped, tables within tempdb will be deleted[dropped].
P: table will be placed into aspstate database, it will be persistent.
C: table will be placed into custom database specified with –d option.
Goto vs2008 command prompt:
Aspnet_regsql –U “sa” –P “nishi” –ssadd –sstype “c” –d “master”
Aspstatetempsessions table will be created in master.
3. Now configure ASP.NET website for storing the session information in Sqlserver.
a) if used a) method in previous step
In Web.Config :
<System.Web>
<SessionState Mode=”SqlServer” SqlConnectionString=”user id=sa;password=”nishi” data source=”localhost”/>
Note:- in SqlConnectionString database name should not be given
b) if used b) method in previous step
In Web.Config :
<System.Web>
<SessionState Mode=”SqlServer” SqlConnectionString=”user id=sa;password=”nishi” database=”master” data source=”127.0.0..1 or systemname” allowcustomsqldatabase=”true”/>
Perfornance :-
Webserver > StateServer > Sqlserver
Consistency:-
Webserver < Stateserver < SqlServer