• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

LEGEND ,
Nov 18, 2016 Nov 18, 2016

Copy link to clipboard

Copied

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,

^_^

Views

376

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Nov 18, 2016 Nov 18, 2016

Add the following to your function:

<cfheader statuscode="404">

Cheers

Eddie

Votes

Translate

Translate
Advocate ,
Nov 18, 2016 Nov 18, 2016

Copy link to clipboard

Copied

Add the following to your function:

<cfheader statuscode="404">

Cheers

Eddie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 18, 2016 Nov 18, 2016

Copy link to clipboard

Copied

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

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 18, 2016 Nov 18, 2016

Copy link to clipboard

Copied

LATEST

You're welcome.

Cheers

Eddie

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation