Session("Session-Name") = Value Session.Add("Session-Name","Value")
Session("Session-Name") Session.Item("Session-Name")
Session.Abandon() '*** Delete All ***' Session.Clear() '*** Delete All ***' Session("Session-Name") = Nothing '*** Delete Some Session ***' Session.Remove("Session-Name") '*** Delete Some Session ***'
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) '*** Create Session ***' Session.TimeOut = 20 Session("SiteName") = "www.ThaiCreate.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>ThaiCreate.Com ASP.NET - Session Object</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>
<%@ 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>ThaiCreate.Com ASP.NET - Session Object</title> </head> <body> <form runat="server"> <asp:HyperLink id="hplLink" runat="server"></asp:HyperLink><br /> </form> </body> </html>
<%@ 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 Cookie 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>ThaiCreate.Com ASP.NET - Session Object</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>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท