How to call cfheader statuscode="404" and prevent IIS custom 404 handler from being called?

644 views
Skip to first unread message

JP

unread,
Sep 21, 2015, 11:07:50 AM9/21/15
to Lucee
I've got a custom 404 handler setup in IIS that executes my 404.cfm page, which works. The problem is that I can't output a 404 status code from within my code without IIS executing my 404 handler. For example, inside a CFM page, if I call:

<cfheader statuscode="404" statusText="not found">

IIS immediately stops processing the page and executes my 404.cfm handler. However, I typically want to output content specific to the 404 error that I am handling inside my code, and I don't want my generic 404.cfm handler to be called. How can I prevent my 404 handler from being called in this case?

My questions are:

1. Is there a way to tell IIS to call my generic 404.cfm handler only when a file or directory doesn't exist?

or 

2. If I can't tell IIS to not execute my 404 handler, how could I pass data to my 404.cfm handler when I call cfheader? If I could do this, then I can pass custom content and my problem is solved. I determine that setting a request variable doesn't make it to the handler, probably because a new request is being created in IIS. I also don't want to use the session scope because it's not enable it for search spiders.

JP

unread,
Sep 21, 2015, 11:31:23 AM9/21/15
to Lucee
I think I figured it out... I added existingResponse="PassThrough" to my httpErrors element in web.config file. The element looks like this:

        <httpErrors errorMode="Custom" existingResponse="PassThrough">
           
<remove statusCode="404" subStatusCode="-1" />
           
<error statusCode="404" prefixLanguageFilePath="" path="/404.cfm" responseMode="ExecuteURL" />
       
</httpErrors>

Bilal

unread,
Sep 22, 2015, 7:42:55 AM9/22/15
to Lucee
Alternately,
You can add this setting to the connector setting file, normally located in c:\windows\BonCodeAJP13.settings

<SkipIISCustomErrors>True</SkipIISCustomErrors>

This will let you control status codes other than 200 with custom messages from Lucee. IIS will still be able to use the standard 404-custom error page for non-cfm related error handling, e.g. when a non-existing image file is requested etc.

Best,
Bilal


Reply all
Reply to author
Forward
0 new messages