我正在尝试使用 Application.cfc 中的 onMissingTemplate() 方法在我的 ColdFusion 应用程序中处理 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 的客户错误消息。
这证明代码没问题,问题出在我的开发环境中,但我找不到。任何想法为什么我仍然得到默认的 CF 错误页面?