I need to inspect all of my existing Session Variables. How can I accomplish this in C#?
I see that VB has a handy "Session.Contents" collection that can be looped through. I need something similar in C#, but I have not been able to find a similar solution.
In C# you can loop through Session using Session.Count that will give you max count now you can use this count in your for loop
or you can use Session.Keys that will return you all keys which are present in current session
Thanks & Regards
Sandeep
If you want something you never had,
do something you have never done!
Actually, this works fine in the Code behind file--which solves my problem.
However, I was initially trying to access the Session object from a Business Logic Layer, and I did not see Session object available at that level. For example, in my BLL whenever I type in Session, the intellisense no longer gives me Session.Add, Session.Contents,
etc. Is there a way that I can access Session from someplace other than .aspx? I've looked at the various System includes and those don't seem to have any bearing on this issue.
I was hoping to have a BLL.Global.ClearSessionDataSetVars() that could be called from multiple places.
Jason Duncan
Member
413 Points
222 Posts
How can I get a list all Session variables?
Apr 17, 2008 08:32 AM|LINK
I need to inspect all of my existing Session Variables. How can I accomplish this in C#?
I see that VB has a handy "Session.Contents" collection that can be looped through. I need something similar in C#, but I have not been able to find a similar solution.
Any help would be appreciated.
Thanks! Jason
ramblor
Contributor
6676 Points
1013 Posts
Re: How can I get a list all Session variables?
Apr 17, 2008 09:31 AM|LINK
I think something like either of these should work:
sandeep_akha...
Member
112 Points
45 Posts
Re: How can I get a list all Session variables?
Apr 17, 2008 09:35 AM|LINK
In C# you can loop through Session using Session.Count that will give you max count now you can use this count in your for loop
or you can use Session.Keys that will return you all keys which are present in current session
Sandeep
If you want something you never had,
do something you have never done!
Jason Duncan
Member
413 Points
222 Posts
Re: How can I get a list all Session variables?
Apr 17, 2008 03:10 PM|LINK
Thanks! Works perfectly.
Jason Duncan
Member
413 Points
222 Posts
Re: How can I get a list all Session variables?
Apr 17, 2008 03:23 PM|LINK
Actually, this works fine in the Code behind file--which solves my problem.
However, I was initially trying to access the Session object from a Business Logic Layer, and I did not see Session object available at that level. For example, in my BLL whenever I type in Session, the intellisense no longer gives me Session.Add, Session.Contents, etc. Is there a way that I can access Session from someplace other than .aspx? I've looked at the various System includes and those don't seem to have any bearing on this issue.
I was hoping to have a BLL.Global.ClearSessionDataSetVars() that could be called from multiple places.
Just wondering (and thanks again),
Jason
ramblor
Contributor
6676 Points
1013 Posts
Re: How can I get a list all Session variables?
Apr 17, 2008 03:27 PM|LINK
Jason Duncan
Member
413 Points
222 Posts
Re: How can I get a list all Session variables?
Apr 17, 2008 03:35 PM|LINK
Thanks again, that was it!