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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variables... gone.... 2

Status
Not open for further replies.

0ddball

Technical User
Nov 6, 2003
208
GB
HI hi hi,

I've got a little problem with some wayward session variables. Let me explain.

I am trying to persist an object to another page so naturaly I stuck it in the Session collection.

Code:
DezRezUser dru = new DezRezUser(AccessCode.Value, "448", BID.Value);
Session["DezRezUser"] = dru;

Right - so I carried on making my page, never stopping to think I might have a problem.

In my Page_Load event I added a redirect for if certain conditions were met.

Code:
if (responseUrl != null && Session["DezRezUser"] != null)
{
Response.Redirect(responseUrl);
}

Origionaly I didn't have the second clause in there - but I've been trying to debug this problem. Needless to say the conditional line executes and the page is redirected.

So now we're on our new page and I want that object back.

Code:
DezRezUser dru = null;

if (Session["DezRezUser"] != null)
{
	dru = (DezRezUser)Session["DezRezUser"];
}
else	// The user has not logging in.
{
	Response.Redirect("~/DezRez/Login.aspx", true);
}

No matter what I do - my Session["DezRezUser"] object has gone. Session.Count == 0! So I did a scooby-doo double take with the classic "wuwwugh?" noise and I've spent the rest of the day trying to get my variable back.

Any ideas?


Yet another unchecked rambling brought to you by:
Oddball
 
Session variable update - much questing later I still have not found the answer to the terrible blight which is affecting my kingdom.... erm... wait...

I've checked that I'm maintaining the same session ID...

I am - so it's not that.

Any ideas?


Yet another unchecked rambling brought to you by:
Oddball
 
I had an app that worked fine at work, but when I moved it to my home computer the session stopped working. Found that my firewall was the issue, turned it off and everything worked fine. Give it a try.
 
I'm currently debugging the app on my development system at work. I've never had this problem with any other application before.

I've published it to our staging server and it doesn't work there either. I've tried it in Firefox and in IE.

I'm at my wits end. I assume it's something to do with Response.Redirect loosing my sesssion variables.

When I get back to work later today I'm going to try and create the object at Session_Start rather than when they try and log in (the reasoning behind my managing logins like this is long, weird and annoying - don't worry, it's not my standard practice - needless to say, I have to do it this way).

Has anyone come accross any problem - possibly with the asynchronous nature of the page call. I always though that the Session object collection did not get 'updated' but rather was a live, normal object collection that when I called add() on, added to.

It seems that because I try to access the Session object before the execution of my previous page has finished the objects I created in that previous page are not available yet.

Can anyone verify this?


Yet another unchecked rambling brought to you by:
Oddball
 
It seems that because I try to access the Session object before the execution of my previous page has finished the objects I created in that previous page are not available yet.

Can anyone verify this?
That shouldn't be the case and it seems like something odd is going on. How do you set the timeout period of the session and what is it currently set to? Could there be anything that is modifying this timeout?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
like where you're coming from there ca8msm. I'll check it when I get back to my codebase.

The only thought I have on that is that I still have the same session ID. If the session times out I would get anotherone, wouldn't I?

During the processing of the page I make and send another HttpWebRequest as well as reveive the reply from it. Do you know if the HttpWebRequest or HttpWebResponse objects have any interaction with the Session collection?


Yet another unchecked rambling brought to you by:
Oddball
 
Yeah, actually I must admit I forgot you had said you had the same session ID!

Can you come up with a simple test harness that replicates the problem and then we can see if we can spot the problem by testing it here?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ok - I'll see what I can do.

I've not yet managed to escape the clutches of home life and make it back to my office so I'm still waiting to try a couple of other suggestions on here.

I'll try and replicate the error.


Yet another unchecked rambling brought to you by:
Oddball
 
Hmmm...I do believe you but it's going to be quite tricky to get to the exact problem unless you can come up with something that we can use to replicate the problem. Can you trim your code down to come up with a simple test that we can copy?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I've tried - they behave.

It's really odd. I can't believe that just this app is having a problem. I just needed to make sure that I wasn't going mad - those pictures are as much for me as everyone else :)


Yet another unchecked rambling brought to you by:
Oddball
 
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using NetTools;

public partial class DezRez_Login : System.Web.UI.Page
{
	string responseUrl = null;

	protected void Page_Init(object sender, EventArgs e)
	{
		if (IsPostBack)
		{
			Session["MooCow"] = new Object();
			responseUrl = "/DezRez/AppVendEdit.aspx";
		}
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (responseUrl != null && Session["MooCow"] != null)
			Response.Redirect(responseUrl);
	}
}

And still it disappears


Yet another unchecked rambling brought to you by:
Oddball
 
I've checked through the Web.config and Global.asax and neither of them will affect the Session.

The session ID persists.

I'm going to try this setup in another application. I say they behave but I've just realised I didn't redirect in the pageload (this problem happens no matter where I redirect).


Yet another unchecked rambling brought to you by:
Oddball
 
[!]I have solved this problem[/!]

Thanks to all you folks out there in Tek-Tips land (that's you, ca8 and hamking).

Here's the lowdown on what I did:

On spotting that it wasn't maintaining the state but WAS keeping the same session ID I realised that something was killing my session. If ASP.net has no other pressing reason to it will not generate a new session ID - it'll just ues an old one. This was happening to me.

There is a very useful article at which pointed me in this direction.

So I changed my redirection method to Server.Transfer (after fixing it's perchant to crash unexpectedly - a different and as yet unanswered story) and told it to maintain the page state (including the cookie jar).

This allowed me access to the correct session in the next page. Groovy.

So then I got to thinking why the page wasn't working with Response.Redirect. I can only assume that because I was redirecting before things like Render had fired the cookies weren't written to the page yet and the postback wasn't getting the correct session cookie.

Gosh - that was a tricky one.


Yet another unchecked rambling brought to you by:
Oddball
 
Thanks for posting your solution...it's often very hard to figure out problems like this, especially when they are hard to re-create.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top