Session problem....

D

Darren Clark

I am having some troubles with Sessin varables dieing..

Basically ihave my own class structure called USER that once the user logs in i save it to a session var called
Session["userdetails"] = myUserObject;

All this works fine until sometimes it is like my sessoin vars just die and then trying to do a cast on them will result in a invalid cast error EVEN though the object is the same type..

I am not sure if the problem is that i am using forms authentication and that it times out AFTER session vars timeout...
eg the session is diing yet the forms authentication is still alive... as i can still view the page.. but my session vars arent there anymore.
Whereas if the forms authentication was dead it should refuse access to the page.

Has anyone had any problems like this at all? Can you give me anything to look at?

I am sort of at a loss... as i would think that if the sessoin ends it would call the session_end
and i make sure i signout the forms authentication.

protected void Session_End(Object sender, EventArgs e)
{

FormsAuthentication.SignOut();

}

HELP...
 
D

Darren Clark

Actually... here is the error message that i keep getting.,.
Now the thing is... if the object is there.. the cast works FINE...

BUT

what i dont understand is why the session var is not there? it never gets set to null in code.

So asp.net is doing it somewhere... by why?

and even if it is .. why is session_end being called to Log the user out of the forms authentication THEREFORE redirecting the user to the login page?


--------------------------------------------------------------------------------

Specified cast is not valid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:



Line 31: // Put user code to initialize the page here

Line 32: JobseekerData myJobseeker = new JobseekerData();

Line 33: myJobseeker = (JobseekerData)Session["JobseekerInfo"];

Line 34: DataRow row = myJobseeker.Tables[JobseekerData.TABLE_JOBSEEEKER].Rows[0];

Line 35: Session["UserFirstName"] = row[JobseekerData.FLD_FIRST_NAME].ToString();



Source File: C:\Inetpub\wwwroot\JR\JobSeeker\JobSeekerHome.aspx.cs Line: 33

Stack Trace:



[InvalidCastException: Specified cast is not valid.]

JR.Web.JobSeeker.JobSeekerHome.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\JR\JobSeeker\JobSeekerHome.aspx.cs:33

System.Web.UI.Control.OnLoad(EventArgs e)

System.Web.UI.Control.LoadRecursive()

System.Web.UI.Page.ProcessRequestMain()





--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.903


I am having some troubles with Sessin varables dieing..

Basically ihave my own class structure called USER that once the user logs in i save it to a session var called
Session["userdetails"] = myUserObject;

All this works fine until sometimes it is like my sessoin vars just die and then trying to do a cast on them will result in a invalid cast error EVEN though the object is the same type..

I am not sure if the problem is that i am using forms authentication and that it times out AFTER session vars timeout...
eg the session is diing yet the forms authentication is still alive... as i can still view the page.. but my session vars arent there anymore.
Whereas if the forms authentication was dead it should refuse access to the page.

Has anyone had any problems like this at all? Can you give me anything to look at?

I am sort of at a loss... as i would think that if the sessoin ends it would call the session_end
and i make sure i signout the forms authentication.

protected void Session_End(Object sender, EventArgs e)
{

FormsAuthentication.SignOut();

}

HELP...
 
C

Calvin Luttrell/ProjectThunder.com

Darren,

Try using the state server instead of in process state management. There are too many things that can cause the ASPNET process to restart which kills the sessions when running in process.


-Calvin Luttrell
ProjectThunder.com

I am having some troubles with Sessin varables dieing..

Basically ihave my own class structure called USER that once the user logs in i save it to a session var called
Session["userdetails"] = myUserObject;

All this works fine until sometimes it is like my sessoin vars just die and then trying to do a cast on them will result in a invalid cast error EVEN though the object is the same type..

I am not sure if the problem is that i am using forms authentication and that it times out AFTER session vars timeout...
eg the session is diing yet the forms authentication is still alive... as i can still view the page.. but my session vars arent there anymore.
Whereas if the forms authentication was dead it should refuse access to the page.

Has anyone had any problems like this at all? Can you give me anything to look at?

I am sort of at a loss... as i would think that if the sessoin ends it would call the session_end
and i make sure i signout the forms authentication.

protected void Session_End(Object sender, EventArgs e)
{

FormsAuthentication.SignOut();

}

HELP...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top