2011-02-28 62 views
0

我有一個反覆返回以下錯誤的自定義的ColdFusion錯誤頁面,往往後的頁面已經被掃描的一個機器人:ColdFusion錯誤:「元素REMOTEADDRESS在錯誤中未定義。」我如何解決它?

元REMOTEADDRESS是錯誤的,不確定的。 ###(頁碼)發生錯誤。

我不知道爲什麼它會返回這個未定義的元素錯誤,或者如果有辦法解決它,除了刪除#error.remoteAddress#代碼。

我的代碼如下所示:

<cferror type="REQUEST" template="error.cfm" mailto="[email protected]"> 
<cfoutput> 
<ul> 
    <li><strong>Your Location:</strong> #error.remoteAddress# 
    <li><strong>Your Browser:</strong> #error.browser# 
    <li><strong>Date and Time the Error Occurred:</strong> #error.dateTime# 
    <li><strong>Page You Came From:</strong> #error.HTTPReferer# 
    <li><strong>Error Diagnostics</strong>: 
    <p>#error.diagnostics#</p> 
</ul> 
</cfoutput> 

回答

2

沒有在這裏完全理解整個邏輯,如果你希望能夠安全地測試,看是否有變,或結構的成員試圖對其進行評估之前就存在,你可以這樣做

<cfif isDefined("error") AND structKeyExists(error, "remoteAddress")>#error.remoteAddress#</cfif> 
2

remoteAddress僅在request and exception type errors可用,因此顯示錯誤變量之前檢查錯誤類型。

<cfif ListFind("request,exception",error.type)> 
    <li><strong>Your Location:</strong> #error.remoteAddress#</li> 
</cfif> 

你也可以檢查錯誤類型不是「驗證」,但我喜歡成爲一種積極的人。

ps。請注意我關閉了您的清單項目。 ;)

3

您應該使用愛德華的解決方案來驗證變量的存在,或cfparam的值,以便它總是存在:

<cfparam name="Error.remoteAddress" default="No Remote Address" /> 
相關問題