Hi gurus,
I encouter lost session variables trouble when Response.Redirect() to another aspx page.
I set 19 Session variables before redirecting. However, the redirected page's session contains only One variable.The very weir sympton is: If I restart IIS, only for the first IE encounter, the redirected page DOES show all 19 session variables.
Once I close IE, any further IE or IE from any other machine's only shows ONE session variable.I can also reproduce such symptons in VS2005 development environment.
Can someone tell me what I have missed? Thanks!
Here is my very straight-forward code pieces:Page1.aspx C# Code behind: (I assign 19 session variables before redirecting to Page2.aspx)
-----------------------------------------
protected void btnTest1_Click(object sender, EventArgs e)
{
// set session variables
this.Session["_Mode"] = "New";
this.Session["_Action"] = ActionParam;
. . .
// at end Session contains 19 session variables
Response.Redirect(~/Page2.aspx);
}
Page2.aspx C# code behind: (lblDebug shows all session variables)
----------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
foreach (string sName in Session.Contents)
{
this.lblDebug.Text += sName + " = ";
if (this.Session[sName] != null)
{ this.lblDebug.Text += this.Session[sName].ToString() + " <br/> "; }
else
{ this.lblDebug.Text += "null <br/> "; }
}
}My Web.config contains: (Cookie is enabled in all machines)
-----------------------------------
<system.web>
. . .
<sessionState mode="InProc" cookieless="false" timeout="40" />
</system.web>
Here are strange symptons:
---------------------------------------
a) In IIS environment:
i) If I restart IIS, Pages2.aspx WORKS, but only for the first encounter, and shows all 19 session variables.
ii) If I close IE and launch a new IE, Pages2 only shows ONE session variable.b) In VS2005 Development environment:
i) If I launch VS2005 from scratch and run the web project, Page2.aspx WORKS and shows all 19 session variables.
ii) However, if I close the browser and run he web project again, Pages2.aspx only shows ONE session variable.
iii) When I debug the 2nd run:
- In Page1.aspx Session.Count = 19 before Response.Redirect() line
- In Page2.aspx Session.Count = 1 in Page_Load()Please help...
![]() |
-1 |
![]() |
Jansuan:
Response.Redirect(~/Page2.aspx);That should not even compile! should be someting like
Response.Redirect("~/Page2.aspx");
Cheers
Al
My Blog
MapStats.NET
Please click on 'Mark as Answer' if this post answered your question!
![]() |
0 |
![]() |
Hi
use this
Response.Redirect("~/Page2.aspx", false);
this will not end the current thread ,and so the session variables can be set ...
Regards,
Anas Ghanem.
Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!
![]() |
0 |
![]() |
Sorry, that was my typo since I replaced the actual page name . I did code
Response.Redirect("~/Page2.aspx");
![]() |
0 |
![]() |
The link you mentioned is indeed a great article that explains the root cause of the problem.
However, I tried the overload method
Response.Redirect("~/Page2.aspx", false);
It DOES not work for me. I am still not getting the same Session State.
In the linked blog you mentioned, I saw mixed response. Some said the oveload method work, and others said otherwise. I do not see a solid answer as exactly how to make it work. Can you shed morel ight?Page2.aspx does works if I use
Server.Transfer("~/Page2.aspx");
But, this approach causes other issues for me in my real page and it is not the solution I prefer.I notices that in Page2.aspx, the Session.SessionID is changed (that proves Pages2.aspx was assigned a fresh new Session State.) In my post, I said I got onle ONE session variable in Page2.aspx. I was wrong, Page2.aspx actually get NO session variable to begin with.
Regards,
Jansuan
![]() |
0 |
![]() |
Hi
I can't find any clue !
did you have any code that modify some files or applciation directory ? are you modifying the web.config before redirecting to the other page ?
Regards,
Anas Ghanem.
Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!
![]() |
1 |
![]() |
Hi Jan,
Most of the browsers will accept maximum 10 to 15 session variables or cookies. If U try to use nore than it previous contents will be lost.
You can use following options
1. pass variables by querystring (dont' pass sensitive data like password. in such a case session is recommended.
2. use ViewState variable
3. use Request.Forms variable
Important:
![]() |
-1 |
![]() |
HI jansuan,
I realy suprised by the question you asked. But important thing is to be noted that there are good amount of session variables which not all browsers supports or fail to support.Better use query string and pass the value from on page to the others. But if u really want to use the Session variables the one thing u can do.
Make a BE and use all the 19 variables as a property to this BE and use this single BE into ur session. If u have to assign something then typecast it inot that BE and add value to by BE.Property name=<value>
and get it in the same way,
"Mark as Answer" on the post that helped you.
Chandan,
Imfinity India Pte Ltd.
![]() |
0 |
![]() |