coldfusionsession-variablessession-statesessionidapplication.cfc

coldfusion sessionid not being created


I have a ColdFusion 9 application using an application.cfc and it creates the session like it should but when I dump the session there is a cfid and a cftoken and sometimes the urltoken but no sessionid and I can not reference the SESSION.SessionID variable in my code as it says it is undefined.

What would cause it to creat the cfid and the cftoken just fine but no sessionid?

<cfset THIS.Name = "AppNameRedacted" /> 
<cfset THIS.ApplicationTimeout = CreateTimeSpan( 2, 0, 0, 0 ) /> 
<cfset THIS.SessionManagement = true /> 
<cfset THIS.SessionTimeout = CreateTimeSpan( 0, 2, 30, 0 ) /> 
<cfset THIS.SetClientCookies = true />

EDIT: onSessionStart() function

<cffunction name="OnSessionStart" access="public" returntype="void" output="false" hint="Fires when the session is first created."> 
    <cfset var LOCAL = {} /> 
    <cfset LOCAL.CFID = SESSION.CFID /> 
    <cfset LOCAL.CFTOKEN = SESSION.CFTOKEN /> 
    <!--- Clear the session. ---> 
    <cfset StructClear( SESSION ) /> 
    <cfset SESSION.CFID = LOCAL.CFID /> 
    <cfset SESSION.CFTOKEN = LOCAL.CFTOKEN /> 
    <!--- Return out. ---> 
    <cfreturn /> 
</cffunction>

Solution

  • Here are the ColdFusion 9 docs that outline what variables you can expect in the session scope and when.

    In your posted code, you are doing a structClear() on the session scope which is deleting all variables from it. The only two variables you're putting back are CFID and CFTOKEN.