我想在Application.cfc中的onMissingTemplate()方法中處理ColdFusion應用程序中的404錯誤。使用onMissingTemplate()無法處理Coldfusion 8中的404錯誤
我的開發環境是ColdFusion 8(開發版)+ JRun + Linux。在[WEB_ROOT] /testmissing/Application.cfc我有代碼CF文檔:
<cfcomponent>
<cffunction name="onMissingTemplate">
<cfargument name="targetPage" type="string" required=true/>
<!--- Use a try block to catch errors. --->
<cftry>
<!--- Log all errors. --->
<cflog type="error" text="Missing template: #Arguments.targetPage#">
<!--- Display an error message. --->
<cfoutput>
<h3>#Arguments.targetPage# could not be found.</h2>
<p>You requested a non-existent ColdFusion page.<br />
Please check the URL.</p>
</cfoutput>
<cfreturn true />
<!--- If an error occurs, return false and the default error
handler will run. --->
<cfcatch>
<cfreturn false />
</cfcatch>
</cftry>
</cffunction>
</cfcomponent>
當我瀏覽/testmissing/foo.cfm我得到默認CF 「找不到文件...」 錯誤頁面。
我在不同的環境下嘗試了相同的代碼:Coldfusion 9(開發版)+ Apache + Windows。如預期的那樣,瀏覽/testmissing/foo.cfm導致從onMissingTemplate發出custome錯誤消息。
這證明代碼是好的,問題在我的開發環境中,但我找不到它。任何想法,爲什麼我仍然得到默認的CF錯誤頁面?
它們在CF8和CF9環境中都是空的。生產服務器與其他CF應用程序共享,我不想捕捉他們的404錯誤。所以我試圖在應用程序級別上處理404。 – Michlis 2011-03-15 12:20:31