tags:

views:

281

answers:

2

I have an aspx page (page1.aspx) where I set a Session variable and then redirect to another page:

HttpContext.Current.Response.Redirect("page2.aspx");

On page2.aspx I want to read the session variable, but it doesn't exist until I reload the page. I try to read the session variable in page_load.

The weird thing is that it works in firefox, but not in explorer??

(Note that I've simplied this a bit to explain the problem page1.aspx is accessed from my HttpModule that and is rewritepathed (my workaround to get access to Session). So the flow is HttpModule -pathrewrite-> page1.aspx (set session var) -redirect-> page.2.aspx.)

+1  A: 

Try switching your Response Redirect to:

Response.Redirect("page2.aspx",false);
HttpContext.Current.ApplicationInstance.CompleteRequest();

The default Redirect implicitly calls Redirect("url", true) which can cause a thread abort exception. It's possible that could be impacting this.

Chris Marisic
Thanks. You saved my ass. If I could donate rep. points to you I would!
Niels Bosma
I was grasping for straws, previously I've seen weird issues resulting with Response redirect and this was the solution we used there I hoped it'd be that simple for you too. I'm glad it was!
Chris Marisic
+1  A: 

Just for documentation:

Adding ApplicationInstance.CompleteRequest(); didn't really solve my problem (my misstake).

Found a blog entry that describes the problem, whose solution did the trick.

http://forums.asp.net/p/1163911/1931020.aspx#1931020

I.e in page2 I added (on PageLoad):

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1);
Niels Bosma