Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

onSessionEnd not working properly

Participant ,
Jul 09, 2010 Jul 09, 2010

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

TOPICS
Getting started
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 09, 2010 Jul 09, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 09, 2010 Jul 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 09, 2010 Jul 09, 2010

ahhh, ok

thanks to you both

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 09, 2010 Jul 09, 2010
LATEST

You may want to note that your original code would have been throwing "Variable Undefined" errors when it executed.

But since the onSessionEnd() function does not run in response to any request, it has no place to display that message to a user.  So it just logs the error in the ColdFusion logs and quietly dies.

The one thing you could do to catch errors like this is the use the OnError() function in the Applicaiton.cfc.  This would interecept errors in the other Applicaiton.cfc functions (and all the rest of your CFML code) and do something you design with it.  Such as firing off e-mails or in some other maner alert those who would like to be alerted when the code executation throws exepections.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 09, 2010 Jul 09, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources