Results 1 to 11 of 11

Thread: Session won't abandon?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Montreal, QC
    Posts
    24

    Question

    Hello everybody,

    I'm kind of new to ASP, although I've been a VB programmer for a while now, and there's a little thing that's really bothering me, so maybe someone can help me out:

    I have this ASP page, which relies on sessions. When someone clicks on a given link, the page calls itself with a URL parameter to trigger the abandon session. That works great, and the message that the session has been abandonned appears. However, if I then return to the previous page and even click refresh, the session is still alive and well and everything appears to be as before. So what gives, am I missing something?

    Thanks in advance,

    JMik

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    By re-requesting the page from the web server, you are beginning a new session.

    Josh
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281
    Hi,

    In addition to session.abandon, I would set the session variable = " "

    Good luck!

    CG

  4. #4
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Try:


    session.expires=0


    it will never be store in the cache of your browser

    is that what you need!!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Montreal, QC
    Posts
    24
    Hey Guys,

    I want to thank everybody for their help, but unfortunately, none of this seems to work:

    JoshT:
    The whole problem is, it's not starting a new session. The session ID remains the same, despite the fact that the session.abandon was triggered during the last operation.

    compuGeek:
    I'm not sure how I would go about doing this, since Session = "", Set Session = Nothing and Session.Value = "" all seemed to be invalid operations. What did you mean exactly?

    sebs:
    "Expires" doesn't seem to be a valid method of the Session object. Could you explain that a little more?

    Thanks again guys,

    JMik

  6. #6
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281
    You can try:

    Code:
    
    session("NameofSessionVar") = " " 
    
    -or-
    
    session("NameofSessionVar") = NULL
    
    -or-
    
    session.contents.remove 'NameofSessionVar' (sans the quotes)

  7. #7
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    sorry, i meant
    response.expires = 0

    sorry, it will work!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Montreal, QC
    Posts
    24

    Exclamation

    Hello again everybody,

    Sebs, expiring the page didn't seem to have any effect either, which is getting very puzzling.

    CompuGEEK, I'm not using session name variables in the way you describe, which leads me to believe that maybe I don't understand this whole session thing at all. This is the way I currently have it set up when a user visits the page:

    1) The page checks the current Session ID value and compares it to the value stored within the user's cookie.

    2) If there is a match, brings the user to the main page.

    3) If not, presents the login page. Once the user logins successfully, the current session's ID is stored in the user's cookie and then goes back to 1.

    So, given this system, I don't see why I would need to use session name variables... Unless I'm missing something?

    Thanks to everyone for their help,

    JMik

  9. #9
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281
    JMik,

    But how are you initializing your session ID variable? Could you post your code?

    Cool

    CG

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Montreal, QC
    Posts
    24
    Sure, here it is... I trimmed it a bit (it was quite long), but the principals are intact.



    Code:
    	Function ValidLogin
    	
    		Dim strEmail
    		Dim strPass
    		
    		strEmail = Request.Form.Item("Addr")
    		strPass = Request.Form.Item("Pwrd")
    		
    		If Trim(strEmail) = "" Or Trim(strPass) = "" Then
    			ValidLogin = False
    		Else
    		
    			OpenDB
    		
    			If ValidEmail(strEmail) And CorrectPassword(strEmail, strPass) Then
    				ValidLogin = True
    			Else
    				ValidLogin = False
    			End If
    			
    			CloseDB
    			
    		End If
    	
    	End Function
    
    	'----------------------------------------------
    
    	Function ValidCookie
    	
    		If Trim(strUserID) = "" Or Trim(strSessionID) = "" Then
    			ValidCookie = False
    		Else
    		
    			OpenDB
    			
    			' ValidEmail is a simple function that checks to see if the user id exists in the database. Returns true if it does.
    			If strSessionID = Session.SessionID And _
    			   ValidEmail(strUserID) = True Then
    				ValidCookie = True
    			Else
    				ValidCookie = False
    			End if
    			
    			CloseDB
    			
    		End if
    	
    	End Function
    
    	'----------------------------------------------
    
    	strUserID = Request.Cookies("ThisPage")("UID")
    	strSessionID = Request.Cookies("ThisPage")("SID")
    
    	'----------------------------------------------
    
    	If ValidCookie Then
    
    	'> Valid Cookie
    
    		' Check for url parameters
    		If Request.Form.Count = 0 And Request.QueryString = "" Then
    
    			' No Parameteres, display main page
    			DisplayMainPage()
    
    		Else
    		'> Parameters were specified
    		
    			If Request.QueryString <> "" Then
    			
    				If Instr(1, Request.QueryString, "=") = 0 Then
    			
    					Select Case LCase(Request.QueryString)
    						Case "goodbye"
    							Response.Write("Goodbye!")
    							Session.Abandon
    						Case Else
    							Response.Write("Sorry, this is not a valid request.")
    					End Select
    					
    				End If	
    				
    			End If
    		
    		End If
    	Else
    
    	'> Invalid Cookie
    	
    		If Request.Form.Count = 0 And Request.QueryString = "" Then
    
    			DisplayLoginPage()
    
    		Else
    		
    			If ValidLogin Then
    
    				'Set cookie with this session's id and user id
    			
    				Response.Cookies("ThisPage") = ""
    				Response.Cookies("ThisPage")("UID") = Request.Form.Item("Addr")
    				Response.Cookies("ThisPage")("SID") = Session.SessionID
    
    				'Reload this page
    				
    				Response.Redirect("ThisPage.asp")
    					
    			Else
    				'Bad name or password
    
    				Response.Write("Invalid Login. Your e-mail address or password may be incorrect. Please try again.")
    					
    			End If
    			
    		End If
    		
    	End If


    JMik

  11. #11
    Hyperactive Member compuGEEK's Avatar
    Join Date
    May 1999
    Location
    Mpls,MN,USA
    Posts
    281
    With Session.Abandon, it's important to remember that your session variables aren't actually destroyed until the every script on the page has been processed. So, you could put Session.Abandon as the very last statement of your code.

    Another way is to use a For loop using Session.Contents

    Code:
    <%
      For Each x in Session.Contents
          Session.Contents.Remove(x)  
        End If
      Next
    %>
    Anyway, I hope you're able to find a solution.

    CG

Posting Permissions

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



Click Here to Expand Forum to Full Width