How To Get All Session Variables And Values?
Session variables are very useful, but you must use them carefully because they could spend too much of your memory resources. It could be useful to find out what are current session variables and its values in some scenarios. You can do it with code like this:
[ C# ]
string
SessionVariableName;
string
SessionVariableValue;
foreach
(string SessionVariable
in Session.Keys)
{
// Find Session variable name
SessionVariableName = SessionVariable;
// Find Session variable value
SessionVariableValue = Session[SessionVariableName].ToString();
// Do something with this data
...
}
[ VB.NET ]
Dim
SessionVariableName As
String
Dim
SessionVariableValue As
String
For
Each SessionVariable As
String In
Session.Keys
' Find
Session variable name
SessionVariableName
= SessionVariable
' Find
Session variable value
SessionVariableValue
= Session(SessionVariableName).ToString()
' Do something with this data
...
Next
Related articles:
1. How To Link CSS file to ASP.NET page?
2. Build Notepad ASP.NET Web Application - part 2 of 2