3
votes

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>
1
Can you provide a repro case that demonstrates this? Should just need an Application.cfc with the relevant app settings, and onRequestStart() with a writeDump(session) in it. Is it CF9 or 9.0.1 or 9.0.2? Windows or *nix? - Adam Cameron
@Renshi - After you move the code into the question, you can delete the redundant comments. - Leigh
It is not that the key is not created. You are deleting it (and any other keys in the session scope) when you call StructClear. That is why it is undefined later on. - Leigh
@Leigh is right,but why are you setting the session up like that anyway? - Matt Busche
I can't remember where I got it from but it was an application.cfc example. Maybe Ray Camden or Ben Nadal example code. The structclear does make sense though. I'll play with that. - Renshi

1 Answers

3
votes

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.