ページが見つからないときにユーザーフレンドリーなメッセージを表示するカスタム 404 ページを設定しようとしています。とはいえ、私の Web サーバー (IIS 8) は .cfm ページを処理しないため、Application.cfc を使用して onMissingTemplate の cfm ページを処理する簡単なテスト スクリプトを作成しました。
<cffunction name="onMissingTemplate" returnType="boolean" output="true">
<cfargument name="targetPage" type="string" required=true/>
<cfset var emails = "abcd@hotmail.com,abcd@gmail.com">
<cftry>
<!--- Log all errors. --->
<cflog type="error" text="Missing template: #Arguments.targetPage#">
<!--- Send an email with an error message. --->
<cfmail to="#emails#" from="no-reply@site.com" subject="Missing page: #Arguments.targetPage#" type="html">
#Arguments.targetPage# could not be found.
</cfmail>
<cfinclude template="404.cfm">
<cfreturn true />
<!--- If an error occurs, return false and the default error
handler will run. --->
<cfcatch>
<cfreturn false />
</cfcatch>
</cftry>
</cffunction>
上記のコードは、IIS 設定内でシステムのデフォルト ページを 404.cfm に変更するまで正常に動作します。404.cfm ページには、
<cfheader statuscode="404">
および HTML コード。デフォルトのページが変更されるとすぐに、関数は空白のページを返します! これを整理する方法、または .cfm ページの処理も Web サーバーに割り当てる必要がありますか? 誰かが似たようなことを経験しましたか?
編集404.cfm の cfheader が何らかの理由で問題を引き起こしていることがわかります。削除すると、関数はページを返します!