Why is the "ColdFusion SESSION" variable "undefined" after referencing a few lines before?

Launch ColdFusion 8.01 standard on Windows2003 / IIS6

Application.cfc:

<cfcomponent output="false">
    <cfscript>
        THIS.SessionManagement = "Yes";
        THIS.SessionTimeout = CreateTimeSpan(0, 3, 0, 0);
        THIS.ApplicationTimeout = CreateTimeSpan(0, 8, 0, 0);
    </cfscript>

    <cffunction name="onRequestStart" returnType="Boolean" output="false">
        <cfargument name="targetPage" type="string" required="true">

        <cfscript>
            if  (!StructKeyExists(SESSION, "User"))
                SESSION.User = CreateObject("component", "cfc.User");
        </cfscript>
    </cffunction>
</cfcomponent>

Template file Example pseudocode:

    LOCAL.qItems =
        CreateObject(
                "component",
                "cfc.Items"
                ).setUser(SESSION.User).getItems();

    for (i=1; i<=LOCAL.qItems.RECORDCOUNT; i++) {
        LOCAL.Item =
            CreateObject(
                "component",
                "cfc.Item"
                ).setUser(
                    SESSION.User
                    ).setId(LOCAL.qItems["Sku"][i]);
    }

SESSION.User is installed (if not already defined) in onRequestStart()of Application.cfc. The above code works in a template file. The second link to SESSION.Userthrew a message exception Element USER is undefined in SESSION.

Why will SESSION.User detect (do not throw an exception) a few lines earlier, and then throw that exception a few lines later (in milliseconds)?

This happens, perhaps once a day, in different templates throughout the application.

How can I prevent this?

+4
2

, - , NULL SESSION.User.

, i , - .

+7

"SESSION.User = CreateObject (" "," cfc.User "); onSessionStart(), , .

+1

All Articles