Skip to main content
WolfShade
Legend
Nov 18, 2016 3:25 PM UTC
Answered

onMissingTemplate() returns 200 OK; how to return 404?

Hello, all,

I'm trying to set it so that my application will return a 404 error as well as display a custom error page if a template is not found.

My onMissingTemplate code as it currently is:

<cffunction name="onMissingTemplate">

    <cfargument name="template" type="string" required="true" />

    <cfset session.msgTmplt = "true" />

    <cfset this.onRequestStart(arguments.template) />

    <cfset this.onRequest(arguments.template) />

    <cfreturn true />

</cffunction>

Now, if I go to www.domain.com/missing/doesntexist.cfm, I get a 200 response.  How can I pass a 404 response?

V/r,

^_^

    This topic is closed to new replies. Start a new post to keep the conversation going.
    EddieLotter
    EddieLotterCorrect answer
    Inspiring
    Nov 18, 2016 5:51 PM UTC

    Add the following to your function:

    <cfheader statuscode="404">

    Cheers

    Eddie

    3 replies

    EddieLotter
    EddieLotterCorrect answer
    Inspiring
    Nov 18, 2016 5:51 PM UTC

    Add the following to your function:

    <cfheader statuscode="404">

    Cheers

    Eddie

    Translate
    WolfShade
    WolfShadeAuthor
    Legend
    Nov 18, 2016 7:10 PM UTC

    Nailed it, EddieLotter​!  Works like a charm.  Thank you!

    V/r,

    ^_^

    Translate
    EddieLotter
    Inspiring
    Nov 18, 2016 7:11 PM UTC

    You're welcome.

    Cheers

    Eddie

    Translate