Handling 404 errors in Coldfusion 8 with onMissingTemplate() not working
I am trying to handle 404 errors in my ColdFusion app with onMissingTemplate() method in Application.cfc.
My dev environment is ColdFusion 8 (dev edition) + JRun + Linux. In [web_root]/testmissing/Application.cfc I have code from CF docs:
<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>
When I browse /testmissing/foo.cfm I get default CF "File not found:..."开发者_开发百科 error page.
I tried the same code on different environment: Coldfusion 9 (dev edition) + Apache + Windows. Browsing /testmissing/foo.cfm resulted in custome error message from onMissingTemplate, as expected.
This proves the code is ok and the problem is somewhere in my dev environment, but I can't find it. Any ideas why I am still getting the default CF error page?
How are your Error Handlers setup in your CF Administrator? Compare between your CF8 and CF9 environments.
Have you tried without the try/catch in there? Just want to make sure you're not obscuring an issue with cflog.
精彩评论