Skip to main content
Inspiring
July 9, 2010
Question

onSessionEnd not working properly

  • July 9, 2010
  • 2 replies
  • 1342 views

the code in my application.cfc doesn't appear to be running

<cffunction name="onSessionEnd" returnType="void" output="false">

      <cfquery name="deleteCartRows" datasource=#APPLICATION.datasource#>

          DELETE from webCart

          WHERE unique_session_ref = "#session.unique_session_ref#"

     </cfquery>   

</cffunction>

what am I doing wrong ? the unique_session_ref field is of type varchar (mySQL database) - it holds a UUID

This topic has been closed for replies.

2 replies

Inspiring
July 9, 2010

I suspect that you need to change how you are referring the session and application scopes.  From the CF documentation: "Use the SessionScope parameter  to access the Session scope. You cannot reference the Session scope directly; for example, use Arguments.SessionScope.myVariable, not Session.myVariable.  You must use the ApplicationScope parameter to access the Application scope. You cannot reference the Application scope directly; for example, use Arguments.ApplicationScope.myVariable, not Application.myVariable."

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7d40.html

Try this (code not tested):

<cffunction name="onSessionEnd" returnType="void" output="false">
    <cfargument name = "SessionScope" required=true/>
    <cfargument name = "AppScope" required=true/>

    <cfquery name="deleteCartRows" datasource=#arguments.AppScope.datasource#>

          DELETE from webCart

          WHERE unique_session_ref = "#arguments.SessionScope.unique_session_ref#"

    </cfquery>

</cffunction>

You may also want to use CFQUERYPARAM within your CFQUERY, this is unrelated to your session issue.

CFQUERYPARAM:

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f6f.html

Inspiring
July 9, 2010

I should add, what's actually going wrong is that the rows in the webCart table aren't being deleted when the session ends

ilssac
Inspiring
July 9, 2010

JR beat me to the answer, yes you can't use the session scope there.

In the OnSessionEnd() function the session has, as documented, ended.  So you can no longer use the Session scope.  You need to use the arguments.sessionScope variable where ColdFusion copied the session scope just before it ended it.

Inspiring
July 9, 2010

ahhh, ok

thanks to you both