Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Sessions

Status
Not open for further replies.

dcusick

Technical User
Aug 9, 2000
271
US
Okay... I'm new to ASP.NET. Been programming classic ASP for quite some time, and finally started moving onto .NET.

Anyway, I have a User object. Upon login, using Forms authentication, I authenticate the user and my authentication method returns a User object. So I want to store this object in the session, to use throughout my app. So, I set a session variable to this object.

Viewing the pagestate and trace info, I see that this is indeed in the session. However, after I redirect the user to the main page, I cannot grab the session variable. I try to retrieve it, by casting it into a User object, but all I get is a null value. However, on this main page, in the trace info, I still see this session object.

Any ideas why I cannot retrieve it? I'm using the following code to retrieve it

Code:
IUser objUser = (IUser) Session["objUser"];

Thanks in advance for any help...
 
Don't know if this helps, but when using ASP.NET Forms Authentication, I thought there was a User object created anyway that was accessible through HttpContext.Current.User or Context.User.
Is your User object a custom object or are you trying to save this one into the session?
 
I think the problem is in the IUser implementation.
Try the two statements to store/retrive objects using a DataTable for example:
Code:
// save the object in one page
Session["Customers"]=dtCustomers;
Restore the object in another page:
Code:
DataTable dt = Session["Customers"];
obislavu

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top