The Session object is a dictionary of name-value pairs. You can associate any CLR-based object with a key of your choosing and place it in the Session object so it will be there when the next request belonging to that session comes through. Then you may access that piece of data using the key under which it was stored. For example, if you wanted to store some information provided by the user in the Session object, you'd write code like this:
void StoreInfoInSession() { String strFromUser = TextBox1.Text; Session["strFromUser"] = strFromUser; }
To retrieve the string during the next request, you'd use code like this:
void GetInfoFromSession() { String strFromUser = Session["strFromUser"] ; TextBox1.Text = strFromUser; }
The square braces on the Session object indicate an indexer. The indexer is a convenient syntax for express keys-both when inserting data into and retrieving data from the Session object.
Managing session state in ASP.NET is extraordinarily convenient. In ASP.NET, session state may live in a number of places including (1) in proc-in the ASP.NET worker process, (2) on a separate state server running a daemon process, and (3) in a SQL Server database.
Let's start by getting a taste of using session state right now.