</>
Skip to content
ASP lessons (13/40)

ASP — Sessions

Start Session

<%@ Language=VBScript %>
<% Session.Timeout = 30 %>
<html>
<body>
<%
Session("username") = "John"
Session("loginTime") = Now
%>
</body>
</html>

Get Session

<%
Dim username
username = Session("username")

If username <> "" Then
    Response.Write("Welcome, " & username)
End If
%>

Session Properties

PropertyDescription
SessionIDUnique ID
TimeoutMinutes until timeout
AbandonEnd session

Session Methods

<%
' Get session ID
Response.Write(Session.SessionID)

' Set timeout
Session.Timeout = 30

' End session
Session.Abandon
%>

Session Events

<!-- Global.asa -->
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Session_OnStart
    Session("startTime") = Now
End Sub

Sub Session_OnEnd
    ' Cleanup code
End Sub
</SCRIPT>

Mini Practice

  1. Set session variables
  2. Read session variables
  3. Set timeout
  4. Use session events

Up Next

Continue with Application — application state.

Related Topics

Frequently Asked Questions about Sessions

What is Sessions in ASP?

Sessions is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Sessions?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Sessions.

Why is Sessions important in ASP?

Sessions is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.