Welcome to Help4Web.co.uk - Web Design Help, Html Tutorial, Php, Asp , SQL help and CCNA, MCSE definitions!
Google
Webkpop-web.com

     Main Menu

· Home
· Free Downloads
· Computing FAQ
· Contact Us
· Free Software Downloads
· Tech Forum
· Technology News
· Web Design Help
· Your Account
· Your PM



     Web Browser


     Website Links
IT solutions
key technology solutions
Storage Area Network - Business Intelligence
Call Centre
White Papers IT
Learn Korean
Chinese Pop Music
Advertise Kpop
Korean Pop Site Map
Web Design
Pop Music
Chinese Girls
HK Pop Korean Music
Lee Hyori
Hyori
Boa Park Ji Yoon
Baby Vox YG Family
Jeon Ji Hyun
1 Tym Ha Ji Won
Shyne Bi Rain Bi
Shin Mina SM Town
Fly to the Sky
Korean Girls
Nicholas Tse
Web Traffic
보아
Edison Chen
Sung Hi Lee
Shinhwa
Andy Lau Jay Chou
White Papers
Case Study SES
Kelly Chen
Liu Yi Fei Sammi Cheng
Jordan Chan Music
IT Solutions

ASP Lesson 4:- ASP Sessions

(517 reads)   



The ASP Session object
When working with an application, 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 start the application and when you end. But 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 client and it contains information that identifies the user. This interface is called the Session object.

The Session object is used to store information about, or change settings for a user session. Variables stored in the 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. The server creates a new Session object for each new user, and destroys the Session object when the session expires.


When does a ASP Session Start?
A ASP session starts when:

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


When does a Session End in ASP?
An ASP 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, you can set the Timeout property.

The example below sets a timeout interval of 5 minutes:

<%
Session.Timeout=5
%>

To end a session immediately, you may use the Abandon method:

<%
Session.Abandon
%>

Note: The main problem with sessions is WHEN they should end. We do not know if the user's last request was the final one or not. So we do not know how long we should keep the session "alive". Waiting too long for an idle session uses up resources on the server, but if the session is deleted too soon the user has to start all over again because the server has deleted all the information. Finding the right timeout interval can be difficult!

Tip: If you are using session variables, store SMALL amounts of data in them.


ASP Store and Retrieve Session Variables
ASP Session object can store variables in it.

The example below will set the Session variable username to "Mickey Mouse" and the Session variable age to "50":

<%
Session("username")="Mickey Mouse"
Session("age")=50
%>

When the value is stored in a session variable it can be reached from ANY page in the ASP application:

Welcome <%Response.Write(Session("username"))%>

The line above returns: "Welcome Mickey Mouse".

You can also store user preferences in the Session object, and then access that preference to choose what page to return to the user.

The example below specifies a text-only version of the page if the user has a low screen resolution:

<%If Session("screenres")="low" Then%>
This is the text version of the page
<%Else%>
This is the multimedia version of the page
<%End If%>


ASP Remove Session Variables
The Contents collection contains all session variables.

It is possible to remove a session variable with the Remove method.

The example below removes the session variable "sale" if the value of the session variable "age" is lower than 18:

<%
If Session.Contents("age")<18 then
Session.Contents.Remove("sale")
End If
%>

To remove all variables in a session, use the RemoveAll method:

<%
Session.Contents.RemoveAll()
%>


ASP Loop Through the Contents Collection
The Contents collection contains all session variables. You can loop through the Contents collection, to see what's stored in it:

<%
Session("username")="Mickey Mouse"
Session("age")=50dim i
For Each i in Session.Contents
Response.Write(i & "<br />")
Next
%>

Result:

username
age

If you do not know the number of items in the Contents collection, you can use the Count property:

<%
dim i
dim j
j=Session.Contents.Count
Response.Write("Session variables: " & j)
For i=1 to j
Response.Write(Session.Contents(i) & "<br />")
Next
%>

Result:

Session variables: 2
Mickey Mouse
50


Loop Through the StaticObjects Collection
You can loop through the StaticObjects collection, to see the values of all objects stored in the Session object:

<%
dim i
For Each i in Session.StaticObjects
Response.Write(i & "<br />")
Next
%>

  

[ Back to Asp Help | Web Help Index ]






CISSP | CCNA | TFT | WEP | VBScript | Server
Jpop
Kpop
Learn Chinese
Learn cantonese
Sim Free Mobile Learn Mandarin
Kaila yu
Utada Hikaru
Jet Li
Twins HK
Kelly Hu
Aaron Kwok Joey Yung
Maia Lee
Chinese Singles
Andy Lau
Sammi Cheng
JackieCheung
Nicholas Tse
Jay Zhou
Jordan Chan
Kelly Chen
Joey Yung
Park Ji Yoon
SES
Shinhwa
Shin Mina
Shyne
SM Town
DBSK TVXQ
Sung Hi Lee
T Tasha
U;nee
Yoo Seung Jun
Won Bin
YG Family
Korean Girls
Korean Wife
Korean Dating
Korean Husband
Korean Singles
Se7en
Epik High
FinKL
Kpop Banners
1 Tym
BabyVox
Bae Yong Jun
Bi Rain / Rain
International Sim Card
Boa
Click-B
Fly to the Sky
GOD
Ha Ji Won
Hyori

Jang Nara
Jeon Ji Hyun
JTL
Papaya
Lee Soo Young
Grace Park
Se7en
Kpop Kim Hee Sun
Won Bin
Korean Singles
Bae Yong Jun
Speak Korean
Jang Nara
SES
YG Family
Chae Yeon
Detox Patch
Detox
Party Promoter
Phone Card
RHUL
Web Tutorial
Programming
Loans UK
BokuMaro
CV Help Book
Chinese Music
Liu Yi Fei
Edison Chen
Andy Lau
Alyssa Chia
Avril Lavigne
Sean Pau
Kylie Minogue
Dan Truong
Uk Chinese
Chinese Models
Music
Learn Korean
Japanese Girls
Memory Card
CCNA definitions
Freelance Jobs

Produced by Kpop-Web Design Associates, all rights not reserved.
Computer Programming with Internet Marketing and Search Engine Optimisation Software Defined Radio | Loans UK | Phil Leung Here are some sites with current affiliates and partner to our sites, they are recommended however we accept no responsibility for the content which they may contain. Printing | Kpop | Web Guide | Kpop | Korean Music 1 | Korean Music 2 | Korean Music 3 | IT White Paper | CV Help | Server Definition | Firewall | White Papaers | Case Study | Web Cast | Research Paper