Re: Session loses all variables during Response.Redirect

Discussion in 'ASP .Net' started by fadi, Jul 18, 2003.

  1. fadi

    fadi Guest

    Session management in .NET is very very buggy. I am not sure how Microsoft
    shipped .NET with such implementation. There are many reasons (and bugs)
    that causes the session to get lost in .NET.

    aspnet_wp.exe gets recycled due to lack of memory (which is caused by the
    way .Net handles releasing objects from memory) and that removes all stored
    sessions for all users. Work around for this is to use StateServer or SQL
    Server session management.

    Session variables stored in a certain page are not maintained when
    redirecting to another page. This I've seen in .NET 2002 but have not tried
    to duplicate it in .NET 2003 caused by a bug in .NET. Solution was to
    basically delete that page and redo it. If you copy and paste the same code
    of the original page it works fine. just got to get rid of the firt page.

    Session variables not maintained when redirecting in debug mode. I started
    to get this after installing SP2 for .NET 2002. Solution is either not run
    in debug mode, or open a browser window before debugging, start debugger
    (ignore the browser window opened by the debugger) and test the window you
    manually opened.

    Thats my experience with the session objects. Your problem does not really
    reflect any of the above but worth a shot. Also there might be a size limit,
    how big is the image?

    fadi

    "Mark MacRae" <> wrote in message
    news:#...
    > I have searched the newsgroups for this and found a couple of similar
    > situations, but none solved my problem.
    >
    > Basically the click of a button on one webform saves an entity then
    > Response.Redirects back to a list page which lists all the entities in the
    > database belonging to the user who is currently logged in.
    >
    > This works fine most of the time. Except when you use the option to upload

    a
    > new image as part of the entity. I'm not entirely sure that that is
    > relevant though because I have stepped through the code in debug mode and
    > the Session still contains 10 variables right up until end of the save
    > button click event code which is the Response.Redirect
    >
    > When I reach the first line of the Page_Load event on the listing page,

    the
    > Session has lost all of it's variables. Poof! Gone! Why? Is there a

    step
    > in between that I don't know about?
    >
    > I have seen responses that mention that both ASPX pages must be in the

    same
    > project, well they are. And in fact, as I mentioned, the session does not
    > lose the variables most times. Only when a new image is uploaded. Below

    is
    > the chunk of code that is different in that case:
    >
    >
    > if(model.imagePath_NullableString != null) {
    > string tempEventDirName = (string)Context.Session["tempDir"];
    >
    > if(tempEventDirName != null && tempEventDirName != string.Empty &&
    > tempEventDirName != "") {
    >
    > string createdEventDirName =

    Context.Request.PhysicalApplicationPath
    > + "/images/listing_files/" + model.pk;
    >
    > Directory.Move(tempEventDirName, createdEventDirName);
    >
    > }
    >
    > }
    >
    >
     
    fadi, Jul 18, 2003
    #1
    1. Advertising

  2. fadi

    Mark MacRae Guest

    Thanks for the ideas.
    I limit the size of the image to under 20K.

    "fadi" <> wrote in message
    news:...
    > Session management in .NET is very very buggy. I am not sure how Microsoft
    > shipped .NET with such implementation. There are many reasons (and bugs)
    > that causes the session to get lost in .NET.
    >
    > aspnet_wp.exe gets recycled due to lack of memory (which is caused by the
    > way .Net handles releasing objects from memory) and that removes all

    stored
    > sessions for all users. Work around for this is to use StateServer or SQL
    > Server session management.
    >
    > Session variables stored in a certain page are not maintained when
    > redirecting to another page. This I've seen in .NET 2002 but have not

    tried
    > to duplicate it in .NET 2003 caused by a bug in .NET. Solution was to
    > basically delete that page and redo it. If you copy and paste the same

    code
    > of the original page it works fine. just got to get rid of the firt page.
    >
    > Session variables not maintained when redirecting in debug mode. I started
    > to get this after installing SP2 for .NET 2002. Solution is either not run
    > in debug mode, or open a browser window before debugging, start debugger
    > (ignore the browser window opened by the debugger) and test the window you
    > manually opened.
    >
    > Thats my experience with the session objects. Your problem does not really
    > reflect any of the above but worth a shot. Also there might be a size

    limit,
    > how big is the image?
    >
    > fadi
    >
    > "Mark MacRae" <> wrote in message
    > news:#...
    > > I have searched the newsgroups for this and found a couple of similar
    > > situations, but none solved my problem.
    > >
    > > Basically the click of a button on one webform saves an entity then
    > > Response.Redirects back to a list page which lists all the entities in

    the
    > > database belonging to the user who is currently logged in.
    > >
    > > This works fine most of the time. Except when you use the option to

    upload
    > a
    > > new image as part of the entity. I'm not entirely sure that that is
    > > relevant though because I have stepped through the code in debug mode

    and
    > > the Session still contains 10 variables right up until end of the save
    > > button click event code which is the Response.Redirect
    > >
    > > When I reach the first line of the Page_Load event on the listing page,

    > the
    > > Session has lost all of it's variables. Poof! Gone! Why? Is there a

    > step
    > > in between that I don't know about?
    > >
    > > I have seen responses that mention that both ASPX pages must be in the

    > same
    > > project, well they are. And in fact, as I mentioned, the session does

    not
    > > lose the variables most times. Only when a new image is uploaded.

    Below
    > is
    > > the chunk of code that is different in that case:
    > >
    > >
    > > if(model.imagePath_NullableString != null) {
    > > string tempEventDirName = (string)Context.Session["tempDir"];
    > >
    > > if(tempEventDirName != null && tempEventDirName != string.Empty &&
    > > tempEventDirName != "") {
    > >
    > > string createdEventDirName =

    > Context.Request.PhysicalApplicationPath
    > > + "/images/listing_files/" + model.pk;
    > >
    > > Directory.Move(tempEventDirName, createdEventDirName);
    > >
    > > }
    > >
    > > }
    > >
    > >

    >
    >
     
    Mark MacRae, Jul 21, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Natty Gur
    Replies:
    0
    Views:
    466
    Natty Gur
    Jul 16, 2003
  2. Mark MacRae
    Replies:
    1
    Views:
    451
  3. dsmith-nospam@poptech-dot-coop

    ASP.NET loses Session variables when in Debug mode

    dsmith-nospam@poptech-dot-coop, Jan 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    649
    Dimitri Glazkov
    Jan 4, 2005
  4. TCook
    Replies:
    3
    Views:
    11,905
    TCook
    Aug 15, 2006
  5. Sal
    Replies:
    1
    Views:
    992
Loading...

Share This Page