HTTP Session state not stroing all session variables

Posted by Aatish under ASP.NET on 8/30/2009 | Views : 3187 | Status : [Member] | Replies : 1
I am trying to access the session variables through this class.
But when i try ,

System.Web.SessionState.HttpSessionState s = System.Web.HttpContext.Current.Session;
System.Collections.Specialized.NameValueCollection.KeysCollection c = System.Web.HttpContext.Current.Session.Keys;
c = s.Keys;
for(int i=0;i<c.Count;i++)
{
string session_name=c.Get(i).ToString();
if(Session[session_name]==null)
{
Response.Redirect(redirect url);
return;
}
}

But i did'nt get all session variables that i have created.
Any solution.




Responses

Posted by: Vuyiswamb on: 8/31/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Aatish

The Design and the approach we take everyday to build our System can be a Downfall.

I always say let SQL be handled by the Database, Let Sessions be Handled by ASP.NET and Let low level Programming be Handled by the language C#, or VB.NET.

When you are Building a web application dont access the sessions in your Classes, rather convert them to variables in C# before you can pass them to classes. In your Code above you are Accessing a session that might have got null before you use it, and this might lead to a

'Object not set for an instance of a....."

Error. First thing again that i have noted in your code

if(Session[session_name]==null)


Session_name is not declared as a Session. Sessions are declare like this

Session["session_name"]


The Session name must be in quotes.

Can i see how you have Declared the Session ?

Thank you for using DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Aatish, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response