ColdFusion Error: Session.SessionID Not Defined?

Posted on 2009-04-06
Last Modified: 2013-12-24
I'm getting errors "Element SESSIONID is undefined in SESSION."

How is this possible? I was under the impression that a Session.SessionID is ALWAYS defined on each request?
Question by:davidsanderson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 39

Expert Comment

ID: 24078017
you have session management turned on in your cfapplication tag?

If you're using application.cfc (instead of .cfm)  are you doing this command in onApplicationStart or onApplicationEnd  or onSessionEnd ?   Session variables are not available directly in these functions

Author Comment

ID: 24078091
Yes I have session management turned on.

I'm using application.cfc. I'm not calling session.sessionid in this file at all. It does get called outside of this file though.
LVL 19

Expert Comment

ID: 24078112
is there something in your code that clears session variables
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

LVL 39

Expert Comment

ID: 24078115
do you have clear the session structure (perhaps for logout?)

I would start by placing a test at the start of onRequestStart to see if the session.sessionID is defined there (before the bulk of your code is executed)

What version of Coldfusion are you using?   I think session.sessionID started with MX ?

Author Comment

ID: 24078425
Yes, when the login times out, it calls a function that clears the session variables, but then it redirects them (cflocation) back to the login page. This would be another request, correct? So a new sessionid would be defined?

I'm using CF 8.

By the way, I can't reproduce this error, several users are getting this error though.
LVL 39

Expert Comment

ID: 24078512
I have never felt comfortable clearing all session variables because some are used by the system and we can't predict when they are re-created or used.

Coldfusion places cookies to maintain the session, they don't use the session variables directly for session management, they are more like an FYI for us developers.   I am referring to CFID, CFTOKEN and sessionID.    I suspect if you were to kill the cookies, the session may be recreated, but I can't say that clearing out the session variables only would cause them to be recreated (because the cookies still exist).

I have always just cleared the variables that I use.   To make this easier, I add a structure within session to manage this...   session.login.userID  and then just delete the login structure and leave the rest of the session alone..

Author Comment

ID: 24079976
I can't really recode the whole app to use a different session variable structure. This app is HUGE.

I could just do away with the StructClear(Session) statement but I don't want any old session data hanging around if the user logs out.

Any other suggestions?
LVL 39

Accepted Solution

gdemaria earned 125 total points
ID: 24080081
ok, didn't know if you were starting out or what.

You can loop over the session structure and avoid those key variables ...

<cfloop item="kk" collection="#session#">
  <cfif listFindNoCase("cfid,cftoken,sessionID",kk) eq 0>
    <cfset "session.#kk#" = "">

Open in new window


Author Comment

ID: 24080308
That looks good. Should I also include urltoken since that's another built-in variable?
LVL 39

Expert Comment

ID: 24080361
sure, makes sense...

And if there are any that you are maintaining that you don't want to lose, perhaps the session start date/time or something..

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math ( While this method is not o…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question