web 2.0

ASP.NET(vb.net) & Session Variables

ASP.NET(vb.net) Session - Session Object - Session : ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application. HTTP is a stateless protocol. This means that a Web server treats each HTTP request for a page as an independent request. The server retains no knowledge of variable values that were used during previous requests. ASP.NET session state identifies requests from the same browser during a limited time window as a session, and provides a way to persist variable values for the duration of that session. By default, ASP.NET session state is enabled for all ASP.NET applications.

ShotDev Focus:
- ASP.NET(vb.net) Session - Session Object [Create,Read,Delete Session]

Example

Create Session

AspNetSession1.aspx

<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'*** Create Session ***'
Session.TimeOut  = 20
Session("SiteName") = "www.ShotDev.Com"
Session("Name") = "Mr.Weerachai Nukitram"

Me.lblText.Text = "Session Created"

Me.hplLink.Text = "Click here to check"
Me.hplLink.NavigateUrl = "AspNetSession2.aspx"

End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form runat="server">
<asp:Label id="lblText" runat="server"></asp:Label><br /><br />
<asp:HyperLink id="hplLink" runat="server"></asp:HyperLink><br />
</form>
</body>
</html>

Read Session

AspNetSession2.aspx

<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
'*** Read Session ***'
Response.write("Site Name = " & Session("SiteName") & "<br>")
Response.write("Name = " & Session("Name")& "<br><br>")

Me.hplLink.Text = "Click here to delete"
Me.hplLink.NavigateUrl = "AspNetSession3.aspx"
End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form runat="server">
<asp:HyperLink id="hplLink" runat="server"></asp:HyperLink><br />
</form>
</body>
</html>

Delete Session

AspNetSession3.aspx

<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

'Session.Abandon()
Session("SiteName") = Nothing
Session("Name") = Nothing

Me.lblText.Text = "Now Session Deleted"

Me.hplLink1.Text = "Click here to check"
Me.hplLink1.NavigateUrl = "AspNetSession2.aspx"

Me.hplLink2.Text = "Click here to create"
Me.hplLink2.NavigateUrl = "AspNetSession1.aspx"
End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form runat="server">
<asp:Label id="lblText" runat="server"></asp:Label><br /><br />
<asp:HyperLink id="hplLink1" runat="server"></asp:HyperLink><br />
<asp:HyperLink id="hplLink2" runat="server"></asp:HyperLink><br />
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) Session - Session Object

ASP.NET(vb.net) Session - Session Object

ASP.NET(vb.net) Session - Session Object
.
.
.
Download this script.
Download
.
.
.
Property & Method

ASP.NET(vb.net) Session.SessionID() - Session Object
ASP.NET(vb.net) Session.Count() - Session Object
ASP.NET(vb.net) Session.Add() - Session Object
ASP.NET(vb.net) Session.Timeout() - Session Object
ASP.NET(vb.net) Session.Abandon() - Session Object
ASP.NET(vb.net) Session.Item() - Session Object
ASP.NET(vb.net) Session.Keys() - Session Object
ASP.NET(vb.net) Session.LCID() - Session Object
ASP.NET(vb.net) Session.Contents() - Session Object
ASP.NET(vb.net) Session.Contents.Remove() - Session Object
ASP.NET(vb.net) Session.Contents.RemoveAt() - Session Object
ASP.NET(vb.net) Session.Contents.RemoveAll() - Session Object
ASP.NET(vb.net) Session.StaticObjects() - Session Object
ASP.NET(vb.net) Session.CodePage() - Session Object
ASP.NET(vb.net) Session_Start() - Session Object
ASP.NET(vb.net) Session_End() - Session Object
ASP.NET(vb.net) Session & Object Value
ASP.NET(vb.net) Session & Array

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

One Response to “ASP.NET(vb.net) & Session Variables”

  1. 2resultant…

Leave a Reply

You must be logged in to post a comment.