[SOLVED] Session loses all variables during Response.Redirect

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: [SOLVED] Session loses all variables during Response.Redirect

    Ok, don't ask me why, but this solved it:
    Replace the line:
    Directory.Move(tempEventDirName, createdEventDirName);
    With:
    Directory.CreateDirectory(createdEventDirName);
    File.Copy(tempEventDirName + model.imagePath_NullableString,
    createdEventDirName + "/" + model.imagePath_NullableString, true);
    Directory.Delete(tempEventDirName, true);

    Don't ask me why Directory.Move causes the Session to abandon itself, but a
    breakpoint in Global.asax.cs in the Session_End event handler confirms that
    an explicit call to end the Session is made somewhere in .NET's black box
    during the Response.Redirect. By swapping the lines as above, the problem
    is gone. I'm still baffled as to why. Again, I use Directory.Move in
    several nearly identical situations and do not see this behaviour.

    For the waste of the better part of my week, and the stress and frustration
    associated with it, I've afixed a ".NET .SUCKS" poster in my cubicle. I
    feel better already.
    Thanks again to those who tried to help out.
    mark


    "Mark MacRae" <nospam@nospam.com> wrote in message
    news:%23lrqqF6SDHA.1920@TK2MSFTNGP11.phx.gbl...
    > 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 Guest

  2. Similar Questions and Discussions

    1. After redirect back from 3rd party, session variables lost
      Thank you in advance. My ASP page 1 redirect user to third party's website, after the process at third party is finished, in 3rd party's...
    2. SOLVED [PHP] SESSION variables losing data on WinXP?
      In case anyone else runs into this problem, the way I solved it was by reinstalling php with the windows installer from php.net. I'm not exactly...
    3. Adding variables to response.redirect
      I have a page that contains processed variables that I'd like to forward using the response.redirect method. However, because the response.redirect...
    4. Session loses all variables during Response.Redirect
      Hi, Just a hint. If you change anything in the Bin directory of the application the application will be restart and all the session data will be...
    5. PLEASE - Session Variables OR Response.Write querystring to target frame?
      Hi, I'm doing an asp.net app (first one) and NEED to use frames (so please don't tell me not to!). I'm loading a mainframe.htm with two aspx files...
  3. #2

    Default Re: [SOLVED] Session loses all variables during Response.Redirect

    Can I sign that poster? I have had my share of frustration with .NET. As to
    the FileSystemObject, looks like we both ran into problems associated with
    it at same time, where in my case it kept files open even though I issued
    the close command, and even performed dispose on it resulting in IIS being
    locked.
    You may want to upgrade to .NET 2003 since it is pretty much a 3GIG service
    pack to .NET 2002. But it also comes with bugs just not as many.

    fadi

    "Mark MacRae" <nospam@nospam.com> wrote in message
    news:OHONHgUUDHA.1324@TK2MSFTNGP11.phx.gbl...
    > Ok, don't ask me why, but this solved it:
    > Replace the line:
    > Directory.Move(tempEventDirName, createdEventDirName);
    > With:
    > Directory.CreateDirectory(createdEventDirName);
    > File.Copy(tempEventDirName + model.imagePath_NullableString,
    > createdEventDirName + "/" + model.imagePath_NullableString, true);
    > Directory.Delete(tempEventDirName, true);
    >
    > Don't ask me why Directory.Move causes the Session to abandon itself, but
    a
    > breakpoint in Global.asax.cs in the Session_End event handler confirms
    that
    > an explicit call to end the Session is made somewhere in .NET's black box
    > during the Response.Redirect. By swapping the lines as above, the problem
    > is gone. I'm still baffled as to why. Again, I use Directory.Move in
    > several nearly identical situations and do not see this behaviour.
    >
    > For the waste of the better part of my week, and the stress and
    frustration
    > associated with it, I've afixed a ".NET .SUCKS" poster in my cubicle. I
    > feel better already.
    > Thanks again to those who tried to help out.
    > mark
    >
    >
    > "Mark MacRae" <nospam@nospam.com> wrote in message
    > news:%23lrqqF6SDHA.1920@TK2MSFTNGP11.phx.gbl...
    > > 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 Guest

  4. #3

    Default Re: [SOLVED] Session loses all variables during Response.Redirect

    Ok, same problem here with directory.Delete and session , but, what is the solution ?

    Regards
    Edgar
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139