Application and Session Objects in ASP.NET - Our First Session
(Page 2 of 4 )
Sessions in ASP.NET are simply hash tables in the memory with a timeout specified. Consider the following examples
Session
(“username”) = “Aayush Puri”
Session(“color”) = “Blue”
This assigns the values “Aayush Puri” and “Blue” to the session variables “username” and “color”, respectively. If I need to know the “username” or “color” in subsequent pages, I can use Session(“username”), Session(“color”).
Sessions in ASP.NET are identified using 32-bit long integers known as Session IDs. The ASP engine generates these session ID’s so that uniqueness is guaranteed.
Let’s now see how you can configure the session object depending on the requirements of your Web Application.
| Session Type | What it does | Example |
| Session.Abandon | Abandons (cancels) the current session. | |
| Session.Remove | Delete an item from the session-state collection. | Session(“username”) = “Aayush Puri” (Initialize a session variable) Session.Remove(“username”) (Deletes the session variable “username”) |
| Session.RemoveAll | Deletes all session state items | |
| Session.Timeout | Set the timeout (in minutes) for a session | Session.Timeout=30 (If a user does NOT request a page of the ASP.NET application within 30 minutes then the session expires.) |
| Session.SessionID | Get the session ID (read only property of a session) for the current session. | |
| Session.IsNewSession | This is to check if the visitor’s session was created with the current request i.e. has the visitor just entered the site. The IsNewSession property is true within the first page of the ASP.NET application. | |
Next: Application Objects >>
More ASP.NET Articles
More By Aayush Puri