ASP.NET Session

A variable is stored temporary in the computer memory, but sometimes we need to hold data across different pages. Here is when Session Variables come very helpful. They can retain their values as long as the user:

  • Does not close the browser
  • Does not leave the page inactive for a period longer than 20 minutes
    (unless specified otherwise)
  • Does not end its own session (e.g. logout)

 

To create a session variables:

Session(“VariableNameHere”) = “VariableValueHere”

To set a different session time out in minutes:

Session.TimeOut = 40

To remove the session variable:

Session.Contents.Remove(“VariableNameHere”)