Sei sulla pagina 1di 11

Session

Web Server
ASP.Net Worker Process
Client App Domain

Session
Memory

When client makes a first request to the application,ASP.net runtime


will create a block of memory to the client in the web server machine.
This Block of memory is called as session memory.This memory will be
unique to the client with the Time Out of 20 min by default.
Here timeout indicates from the last access of client request not from
creation of cookies.Cookie can represent only plain text not an object
but session memory has an object.
Differences between Session & Cookies
It will be maintained in It will be maintained in
the web server system.So the client system. So it is
it is called as server side called as client side state
management management.
Session can represent Cookie can represent
objects plain text

More security for data Less security for data.

Accessing will be slow Accessing would be


faster.
Limitations of sessions in ASP
In ASP client info is maintained by
the server using its sessionID
irrespective of session object usage.
Sessions in ASP are always cookies
based.
Enabling and disabling of sessions
are not supported in ASP
Sessions in ASP.Net
Sessions in ASP.net can be
Cookies Based ( Default )
Cookieless
It can be stored in database also
(SQL Server)
Syntax
 To get session Info
Session(“variable”) = value
 To Read / Get value
Variable = session(“variable”)
Sessions in ASP.Net
Note:
If the value assigned to the session
variable is a character data then the info
will be maintained in the contents
collection of the session object
If the value assigned to the session
variable is an object then that
information will be maintained in the
static object collection of session object.
Sessions in ASP.Net
By default session state for the application
will be true and hence the contents of the
session object can be used.
In order to disable the session object usage in
the web form then “enable session state”
attribute of the page directive should be set
as false.
In the page directive I.e go to the HTML view
and in that page directive at the start of the
page make the enable session state as =
false.
Syntax 
<% @ page language =“vb”
enablesessionstate=“false”…….%>
Session Object
Session Object  this object can be
used to access session memory
from asp.net web page.
The following are the methods 
1. Add(key,value) where key 
String and value  object
2.Remove(key)
3.Abandon()  to close the session
4.SessionId Properties
5.TimeOut
Points to remember about Session
The default session timeout is 20mins
To set the session timeout
session.timeout = minutes ( specify the
min)
{OR}
In web.config we have tag available for
session
<sessionstate mode=“Inproc”
cookieless=“false” timeout =“minutes” />
Note : the default sessionstate uses
cookies for maintaining the data or info.
Points to remember about Session
To define a session as cookie-less then in
web.config:
<sessionstate mode=“Inproc”
cookieless=“false” timeout=“20” />
note: once the sessionstate is set to
cookieless then the sessionInfo or the
sessionID will be appended to the URL for
each and every webform present in the web
application.
In order to retrieve the sessionID of the client
session.sessionID should be used.
Points to remember about Session
In order to maintain the session info.
On the SQL server database then in
web.config:
<sessionState mode=“sqlserver”
stateconnectionstring=“tcpid=127.0.01:
42424” sqlconnectionstring=
“______(completepath”)
cookieless=“false” timeout=“20” />
Points to remember about Session
In order to clear the session variable present
in the session object contents collection then
“session.contents.remove(“sessionvariable”)”
In order to clear all the items present in the
contents collection then
“session.contents.removeall()” should be
used.
In order to kill the session of the user then
“session.abandon()” method should be used.
To disable the session information for a
specific webform then
enablesessionstate=“false” should be set for
the page.

Potrebbero piacerti anche