为什么ColdFusion SESSION变量“未定义”之后被引用几行? [英] Why is a ColdFusion SESSION variable "undefined" after being referenced a few lines before?
问题描述
在Windows2003 / IIS6上运行ColdFusion 8.01标准
Running ColdFusion 8.01 Standard on Windows2003/IIS6
Application.cfc:
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>
模板文件伪代码示例:
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已设置(如果尚未定义) <> c> c> SESSION.User
的第二个引用已在元素USER在SESSION
中未定义时抛出异常。
SESSION.User is set (if not already defined) in onRequestStart()
of Application.cfc
. The above code runs in a template file. The second reference to SESSION.User
has thrown an exception with the message Element USER is undefined in SESSION
.
为什么SESSION.User在前几行定义(不抛出异常),然后在几行后(毫秒内)抛出这个异常?
Why would SESSION.User be defined (doesn't throw an exception) a few lines before, and then throw this exception a few lines later (within milliseconds)?
这可能在我的申请中每天在不同的模板中发生一次。
This happens maybe once a day in different templates throughout my application.
如何防止这种情况? / p>
How can I prevent this?
推荐答案
这很可能是一个线程安全问题,在你的代码清除会话范围或分配NULL到 SESSION.User
。
It's most likely a thread safety issue with something else in your code clearing out session scope or assigning NULL to SESSION.User
.
我建议,因为你似乎没有本地声明 i
,因此代码不是线程安全的,所以你可能在代码的其他地方有类似的错误。
I suggest that because you don't seem to have a local declaration for i
in your loop, so that code is not thread safe - and so you may have similar errors elsewhere in your code.
这篇关于为什么ColdFusion SESSION变量“未定义”之后被引用几行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!