Ending Session on Revisit (in ASP)

Results 1 to 2 of 2

Thread: Ending Session on Revisit (in ASP)

  1. #1
    Join Date
    Dec 1969

    Default Ending Session on Revisit (in ASP)

    I&#039;ve been struggling with managing sessions that have not been properly closed. After some research, I&#039;ve come to the conclusion that there really is no elegant way to close a session on browser close. The methods suggested out there include using a pop-up window to close the session etc... (which is ugly and for some reason my onUnload doesn&#039;t trigger anyways.) In other words, it seems that you pretty much have to wait for the session to timeout. (Please correct me if I&#039;m wrong.)<BR><BR>So I&#039;ve been trying to reset the session when a user revisits instead. The reason I&#039;m so concerned with closing the previously opened session is because the application I&#039;m creating is very database intensive. If the session is not closed properly because the user closed the browser before logging out or the user&#039;s system crashes, and this user returns to run another query, an error occurs because the database is locked for that session until the session times-out.<BR><BR>Since ASP creates a session tied to a particular computer I thought maybe executing Session.Abandon when the user first enters the site might work. But it doesn&#039;t.<BR><BR>Can some please tell me how to either close a session when the user exits without logging out or close it when the user revisits and his/her previous session hasn&#039;t timed out yet. I open to all suggestions... including using a pop-up window if someone can tell me why the onUnload() doesn&#039;t work. (onBeforeUnload() works and onUnload works if I take out the javascripts for my dhtml menus that are loaded right after the &#060;body&#062; tag -- weird)<BR><BR><BR>A GREAT BIG PRE-THANKS to anyone who might be able to offer some help.<BR><BR>MJL

  2. #2
    Join Date
    Dec 1969

    Default RE: Ending Session on Revisit (in ASP)

    MJL, I also struggled with the same type of issues on several projects, including db intensive projects. I have settled on the Session.Abandon concept you described when the user re-visits the log-in page, the only way to get the the db stuff, so...I guess I am confused as to why you can&#039;t seem to "clear" the session for a user/machine when the user first enters the log in page. Here is how I do it, let me know if you see why this won&#039;t work??<BR>###<BR>In my log in page form, I have a hidden form field named "Go", which has a value of Yes..<BR>&#060;input type="hidden" name="Go" value="yes"&#062;<BR>My log in script (page) posts to itself...<BR>When a user first enters the page, I reference this hidden value, if it is not = "Yes", i then clear the session.<BR>Dim strGo<BR>strGo = request.form("Go")<BR> If strGo &#060;&#062; "Yes" Then Session.Abandon &#039;clear the session if still "live", if strGo does not equal "Yes", then the user has not submitted the form on the same page...<BR>If the user submits the form...<BR> If strGo = "Yes" Then &#039;user submitted form<BR> get database records, etc..<BR> Session("userId") = "whatever" &#039;i assign db values<BR> Session("Name") = "whatever"<BR> response.redirect "your user page"<BR> End If<BR><BR>Hope this makes sense and works for you as well as it works for me..<BR>David<BR><BR><BR><BR><BR>

Posting Permissions

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