为什么onSessionStart()在onRequestStart()之前没有运行?

时间:2014-06-03 12:24:35

标签: session coldfusion coldfusion-8

假设以下网站架构:

/Application.cfc
/index.cfm
/sub/Application.cfc
/sub/index.cfm
/login/index.cfm

现在,这里有一些非常基本的伪代码:

/Application.cfc:

<cffunction name="onSessionStart" returntype="Void" output="false">
    <cfscript>
        SESSION.IsLoggedIn = false;

        return;
    </cfscript>
</cffunction>

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

    <cfscript>
        if  (SESSION.IsLoggedIn)
            REQUEST.Cart = {};
    </cfscript>

    <cfreturn true />
</cffunction>

/sub/Application.cfc

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

    <cfscript>
        SUPER.onRequestStart(ARGUMENTS.targetpage);
    </cfscript>

    <cfif NOT SESSION.IsLoggedIn>
        <cflocation url="/login/" addtoken="false" />
    </cfif>

    <cfreturn true />
</cffunction>

当我请求/sub/index.cfm时,我收到以下异常:Element ISLOGGEDIN is undefined in a Java object of type class [Ljava.lang.String;.

在我的本地开发机器上,我打开了调试信息,所以我可以看到SESSION已初始化,至少从cookie的角度来看,但正如您所看到的,我的SESSION变量未初始化:

Session Variables:
cfid=149415
cftoken=b7740eb6d2219f83-619FF01B-78AC-C0A4-1997EC503DA43982
sessionid=PRUDENTIAL_2UA1130DBK_2_149415_b7740eb6d2219f83-619FF01B-78AC-C0A4-1997EC503DA43982
urltoken=CFID=149415&CFTOKEN=b7740eb6d2219f83-619FF01B-78AC-C0A4-1997EC503DA43982

我无法理解为什么在onSessionStart()之前调用onRequestStart()。不应该首先调用onSessionStart()吗?

0 个答案:

没有答案