這個代碼在Application.cfm中(我知道它應該可能是.cfc,但這是一些可以追溯到MX的舊代碼)用於在CF8和CF9上正常工作的cookie - 但我使用CF10開發人員版將其移至本地目錄,直到我將該塊註釋掉後才能使用。達到索引時出現錯誤。Session Cookies和Application.cfm
The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.
Null Pointers are another name for undefined values.
The error occurred in C:/ColdFusion10/cfusion/wwwroot/TFT/Application.cfm: line 3
1 : <!--- APPLICATION settings --->
2 : <cfif IsDefined("cfid")>
3 : <cfcookie name="cfid" value="#cfid#" expires="NOW">
4 : <cfcookie name="cftoken" value="#cftoken#" expires="NOW">
5 : </cfif>
這是當前代碼Application.cfm:
<!--- APPLICATION settings --->
<!--- 5/1/13 removed cookies temporarily
<cfif IsDefined("cfid")>
<cfcookie name="cfid" value="#cfid#" expires="NOW">
<cfcookie name="cftoken" value="#cftoken#" expires="NOW">
</cfif>--->
<!--- Define the application parameters--->
<cfapplication name="TFTAdmin" clientmanagement="Yes"
sessionmanagement="Yes"
setclientcookies="No"
sessiontimeout="#CreateTimeSpan('0','4','0','0')#"
applicationtimeout="#CreateTimeSpan('0','4','0','0')#">
<!--- Create cookies that disappear when the browser closes as to increase security --->
<cflock scope="session" type="readonly" timeout="5">
<cfcookie name="cfid" value="#session.cfid#">
<cfcookie name="cftoken" value="#session.cftoken#">
</cflock>
編輯:有沒有在這個文件的詳細代碼 - 但似乎無關緊要。
謝謝。我必須在應用程序聲明之後放置(這是有道理的),否則'session'是未定義的。 – Macness 2013-05-03 13:26:32
@Macness上面的答案是不正確的。 'session'不是ColdFusion [範圍評估順序](http://help.adobe.com/zh_CN/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec09af4-7fdf.html)的一部分。因此,有條件的和上面提出的條件是不一樣的。所以代碼可能不會出錯,但它並沒有完成預期的工作。查看我的回答,瞭解我的想法。 – nosilleg 2013-05-07 19:40:17
@nosilleg不知道這是如何使我的答案不正確?問題是'isDefined()'不看會話變量,所以範圍評估順序實際上證明了我的觀點。 – 2013-05-08 01:24:16