Session Object VB NET
Session Object VB NET
NET
--------------------------------------------------
The Session object allows you to store and retrieve user-specific data on the server side. It helps to maintain
------------------------------------
Syntax:
Session("key") = value
Example:
Session("username") = "JohnDoe"
Session("loginTime") = DateTime.Now
------------------------------------------
Syntax:
Example:
Safe Retrieval:
End If
---------------------------------
Session.Remove("username")
Session.Abandon()
5. Session Variables
--------------------
Example:
Session("cartItems") = 5
Session("theme") = "dark"
6. Session Identifiers
-----------------------
-------------------------------------------
Properties:
- SessionID: Unique ID
Methods:
------------------------------------------
Default.aspx:
<asp:Label ID="lblOutput" runat="server" />
Default.aspx.vb:
Session("username") = "Alice"
Session("visitCount") = 1
Else
End If
lblOutput.Text = "Hello, " & name & ". You've visited " & visits.ToString() & " times."
End Sub
Session.Clear()
End Sub
Session.Abandon()
End Sub
-----------------------
- Login System
- Shopping Cart
- Theme Preference
- Form Wizard
10. Summary
-----------
- Persistent
- User-specific
- Server-side
- Easy to use
- Flexible