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"] = null; //*** Delete Some Session ***// Session.Remove("Session-Name"); //*** Delete Some Session ***//
<%@ Page Language="C#" Debug="true" %> <script runat="server"> void Page_Load(Object sender , EventArgs e) { //*** Create Session ***// Session.Timeout = 20; Session["SiteName"] = "www.ThaiCreate.Com"; Session["Name"] = "Mr.Weerachai Nukitram"; this.lblText.Text = "Session Created"; this.hplLink.Text = "Click here to check"; this.hplLink.NavigateUrl = "AspNetSession2.aspx"; } </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="C#" Debug="true" %> <script runat="server"> void Page_Load(Object sender , EventArgs e) { //*** Read Session ***// Response.Write("Site Name = " + Session["SiteName"] + "<br>"); Response.Write("Name = " + Session["Name"] + "<br><br>"); this.hplLink.Text = "Click here to delete"; this.hplLink.NavigateUrl = "AspNetSession3.aspx"; } </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="C#" Debug="true" %> <script runat="server"> void Page_Load(Object sender , EventArgs e) { //Session.Abandon() Session["SiteName"] = null; Session["Name"] = null; this.lblText.Text = "Now Cookie Deleted"; this.hplLink1.Text = "Click here to check"; this.hplLink1.NavigateUrl = "AspNetSession2.aspx"; this.hplLink2.Text = "Click here to create"; this.hplLink2.NavigateUrl = "AspNetSession1.aspx"; } </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 ของทีมงานไทยครีเอท