2. Session
A Session is the time for which a particular user
interacts with a web application.
Sessions helps to preserve data across
successive accesses.
Sessions serve as a way to transport and
maintain user data in web pages, such as
forums, or e-commerce websites.
3. Session Object
When you are working with an application on your
computer, you open it, do some changes and then
you close it. This is much like a Session. The
computer knows who you are. It knows when you
open the application and when you close it.
on the internet there is one problem: the web server
does not know who you are and what you do,
because the HTTP address doesn't maintain state.
ASP solves this problem by creating a unique cookie
for each user. The cookie is sent to the user's
computer and it contains information that identifies
the user. This interface is called the Session object.
4.
Session objects give us the power to preserve
user preferences and other user information
when browsing a web application.
The Session object is user specific.
Variables stored in a Session object hold
information about one single user, and are
available to all pages in one application. Common
information stored in session variables are name,
id, and preferences.
Practical e.g. is the case of an e-commerce
website where the visitor browses through many
pages and wants to keep track of the products
ordered.
5. Methods
Methods
Description
Abandon
destroy all objects stored in a Session
object and releases their resources. If the
Abandon method is not explicitly called,
the web server will maintain all session
information until the session times out.
Contents.Remove
removes the specified item from the
Session object Contents collection.
Contents.RemoveAll
removes all the items from the Session
object Contents collection.
7. When Session starts?
A new user requests an ASP file, and the
Global.asa file includes a Session_OnStart
procedure
A value is stored in a Session variable
A user requests an ASP file, and the
Global.asa file uses the <object> tag to
instantiate an object with session scope
8. When Session Ends?
A session ends if a user has not requested
or refreshed a page in the application for
a specified period. By default, this is 20
minutes.
If you want to set a timeout interval that
is shorter or longer than the default, use
the Timeout property.
9. Session Timeout
<%
response.write("Default Timeout is: " &
Session.Timeout & " minutes.")
Session.Timeout=30
response.write("Timeout is now: " &
Session.Timeout & " minutes.")
%>
O/P:
Default Timeout is: 20 minutes.
Timeout is now: 30 minutes.
10. Problem with Session Object
The Session object is based on using
cookies, so if cookies are not permitted or
disabled on the client browser (because of
firewall issues, browser incompatibility, or
desktop/network security concerns), the
Session object is rendered useless.