2

我正在尝试使用 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 错误页面?

4

2 回答 2

0

您的 CF 管理员中的错误处理程序是如何设置的?比较您的 CF8 和 CF9 环境。

于 2011-03-14T16:56:14.650 回答
0

你试过没有 try/catch 吗?只是想确保您没有掩盖 cflog 的问题。

于 2011-03-17T21:41:07.927 回答