Skip to main content
Inspiring
January 23, 2013
Question

CF10 and IIS 7.5 - cfheader in 404 custom error handler not working correctly

  • January 23, 2013
  • 2 replies
  • 14694 views

I'm getting some really weird behavior when handling 404 errors after updating to CF10 using IIS 7.5 on a Win2k8 R2 x64. IIS randomly delivers only a portion of the HTML page when I set the 404 status code using <cfheader statuscode="404" statustext="Not Found"> inside my 404 handler page (/404.cfm).

In IIS, I specify "/404.cfm" (execute a URL) as my custom error handler page for 404 errors, which in turn calls <cfheader statuscode="400" statustext="Not Found">. This has worked really well up through CF9. However, after updating to CF10, something is broken.

When I remove the code: <cfheader statuscode="404" statustext="Not Found"> from my 404.cfm page, the problem goes away, but so does the 404 status code, which means that search engines will see this as a legitimate document. The question is, how can I return both the content of my 404.cfm page (it simply suggests other pages that the user might be looking for) AND the 404 not found status code?

Any ideas?

2 replies

Participating Frequently
June 7, 2013

I found a pretty good work-around for this after literally days of trial and error, testing all the other suggestions out there include the one above (none of which ever worked 100% for one reason or another).

For this situation, leave all the default IIS 7.5 error settings.  You won't be touching IIS for any of this.  However, you will need to create a web.config file on your root that looks like this (which will overwrite any IIS settings you have anyway):

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

  <system.webServer>

    <httpErrors existingResponse="PassThrough" />

  </system.webServer>

</configuration>

The PassThrough setting turns off IIS error handling altogether basically, and allows CF to handle errors via your mappings in CF admin for the missing template handler and the site-wide error hander.  You should set those to whatever you want in CF admin to handle your 404's and 500's, and throw the appropriate CFHEADER status for each.

The last remaining problem was how to handle 404's for directories and non-cfm files that don't exist since those requests would be bypassing CF and IIS is set to ignore.  Those kinds of pages would come back BLANK with 0 byte, and although the 404 header status code was correct, it's not very user-friendly.  The solution  was to use my existing ISAPI Rewrite module to force a custom 404 when a non-cfm file or directory is found, like this:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /error404.cfm [NC,L,NS]

Using this setup, I am able to use my custom CF 404/500 error handers like how it worked in IIS 6, AND, still get proper header codes and proper handling for non-CF files and directories.  I would be intersted to hear back whether this does or does not work for people.  Hopefully it saves someone some time.

P.S.  My post is a summary of all the advice given on this page, so most credit goes here (I pretty much ruled out everything else): http://stackoverflow.com/questions/4968018/coldfusion-error-and-iis7-5-error-pages

New Participant
February 27, 2013

Have you had any success getting past this?  While working on migrating our site to CF10 (also on 2008 R2) I found myself with almost the same issue.  Anytime I add <cfheader statuscode="404" statustext="Not Found"> inside our 404 handler, the server responds with:

          HTTP/1.1 200 OK

          Server: Microsoft-IIS/7.5

          X-Powered-By: ASP.NET

          Date: Wed, 27 Feb 2013 21:13:58 GMT

          Content-Length: 0

and a completely blank (no html at all) page - as one would expect with a content-length of 0.

Inspiring
February 27, 2013

Thanks for the reminder... I have not figured this out and it's a critical problem for me. I cannot get my custom 404 handler to output a complete document. Sometimes the page outputs nothing, other times it outputs 1 or 2K and other times more. But it's not consistent, and I cannot report 404 errors for the time being. I've tried everything that I can think of. Please keep me posted on this thread if you find anything out, and I'll do the same.

FYI, I did post a bug here:

https://bugbase.adobe.com/index.cfm?event=bug&id=3488063

You should vote for it, and/or add your comments.

I also created a thread here:

http://stackoverflow.com/questions/15125471/problems-handling-404-errors-in-coldfusion-10-on-win2k8-r2-x64

New Participant
August 12, 2013

I tried the suggestion given in 3. martypaz using the code in a 404.cfm page with CF 10 and IIS 7 64bit and custom /404 page defined in IIS for the site.  It works for a non-existent HTML or HTM page, but still get a blank page when a missing .CFM page.

Thought would add my comment here to see if any good solution has been found to this problem.  Would be nice if there was a straightforward and reliable solution that has turned up, or a fix addressing this by Adobe.


Replying to myself, as apparently can't edit my previous entry.  As other posts have shown update 11 for CF10 did not provide a solution for all. 

It appears that IIS takes control and does not allow the CFM code to execute when using /404.cfm for the custom error page when a missing .cfm page is called.  However since it did work for a missing .htm page, I used a call to a missing HTM page to display the custom 404.cfm page, then viewed the source code, copied it and created a 404.html page.  IIS then set to /404.html and now get the custom page for both .htm and .cfm missing pages.  Obviously have lost any on-the-fly CFM code flexibility, but at least have a page response.

Hopefully Adobe will come up with a good solution to this rather serious bug soon so all of these various work-arounds can be dispensed with.