Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,025

HOME > ASP.NET > ASP.NET Object > ASP.NET Session Variables



Clound SSD Virtual Server

ASP.NET Session Variables

ASP.NET Session Variables() ใน ASP.NET เป็น Object ที่ใช้สำหรับการเก็บข้อมูลของ Client แต่ล่ะคนโดยแต่ล่ะ Client แต่ค่าตัวแปรทั้งหมดถูกจัดเก็บไว้ฝั่ง Web Server โดยจะมีหมายเลข Session ID ที่ไม่ซ้ำกัน เป็นตัวกำกับและคอยติดตามเก็บตัวแปรที่เกิดขึ้นภายในโปรแกรมภายใต้ตัวแปร Session ตัวแปร Session เป็นตัวแปรแบบ Global คือเมื่อมีการประกาศตัวแปรแล้ว จะสามารถเรียกใช้งานได้ในทุกส่วนของโปรแกรม และตัวแปร Session จะหายไปเมื่อมีการปิด Browser/ปิดเครื่อง Client หรือหมดอายุของ Session

Language Code : VB.NET || C#

Syntax

Session[.collection|property|method|event]


ค่าตัวแปรที่เกิดขึ้นภายใน Session จะเป็นตัวแปรที่ระบุ Client อย่างแน่นอน และจะไม่มีการเกิดข้อผิดพลาดและซ้ำซ้อนระหว่าง Client อื่น ๆ ซึ่งถ้าจะทำความเข้าใจง่าย ๆ คือ ค่าตัวแปรของแต่ล่ะ Client จะเป็นของใครของมัน ไม่เกี่ยวข้องกัน ซึ่งจะต่างกับตัวแปร Application ซึ่งจะเป็นการใช้ตัวแปรร่วมกันทั้งระบบ

การสร้างตัวแปร Session (Create Session)

Session("Session-Name") = Value
Session.Add("Session-Name","Value")



การอ่านตัวแปร Session (Read Session)

Session("Session-Name")
Session.Item("Session-Name")



การลบตัวแปร Session (Delete Session)

Session.Abandon() '*** Delete All ***'
Session.Clear() '*** Delete All ***'
Session("Session-Name") = Nothing '*** Delete Some Session ***'
Session.Remove("Session-Name") '*** Delete Some Session ***'


Application Object



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.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>



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>ThaiCreate.Com ASP.NET - Session Object</title>
</head>
<body>
    <form runat="server">
        <asp:HyperLink id="hplLink" runat="server"></asp:HyperLink><br />
    </form>
</body>
</html>









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 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>


คำอธิบาย

AspNetSession1.aspx เป็นการสร้างตัวแปร Session (Create Session)
AspNetSession2.aspx เป็นการแสดงค่าตัวแปร Session (Read Session)
AspNetSession3.aspx เป็นการลบค่าตัวแปร Session (Delete Session)

Screenshot

ASP.NET Session Object

ASP.NET Session Object

ASP.NET Session Object









ASP.NET Session (DataSet & DataTable)

ASP.NET ArrayList & Session

ASP.NET HashTable & Session

ASP.NET SortedList & Session

ASP.NET StringDictionary & Session

   
Share

Property & Method (Others Related)

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

ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-26 21:51:26 / 2017-03-28 22:05:51
  Download : Download  ASP.NET Session Variables
 Sponsored Links / Related

 
ASP.NET Response
Rating :

 
ASP.NET Request
Rating :

 
ASP.NET Request.Form
Rating :

 
ASP.NET Request.QueryString
Rating :

 
ASP.NET Cookies Variables
Rating :

 
ASP.NET Global.asax
Rating :

 
ASP.NET Application Variables
Rating :

 
ASP.NET Server Variables
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่