ASP.Net Session data lost between pages

17,752

I was having exactly the same problem and in my case I found the cause of this behavior. It turned out to be that when I was invoking the Response.Redirect() method I was using the full url instead of just the page name. So when I was in localhost/myapp/page1.aspx I redirected to MYMACHINENAME/myapp/page2.aspx and that's why the sessions were different for each page. I corrected this in my code using only "page2.aspx" and then the final url on any browser (IE, firefox) was localhost/myapp/page2.aspx.Don't know if you're playing with the urls the way I was doing it but maybe this answer can give you a clue. Thanks and good coding

Share:
17,752
Ananth
Author by

Ananth

Updated on June 09, 2022

Comments

  • Ananth
    Ananth almost 2 years

    I came across a weird behavior today w/ my web application. When I navigate from a page to another, I lose one particular session variable data.

    I'm able to launch the app in firefox and able to see that the session data is not lost.

    I use Response.Redirect(page2, false) to redirect to another page.

    Below code was used to track session variables

    System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\test.txt", true);
    for (int i = 0; i < Session.Count; i++)
    {
     sw.WriteLine(Session.Keys[i] + " " + Session.Contents[i]);
    }
    sw.Close();
    

    Can anyone help me in this? Any help is appreciated.