Skip navigation
redtopia-dev
Currently Being Moderated

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

Jan 23, 2013 2:25 PM

Tags: #windows #iis #404 #cfheader #cf10 #404_error

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?

 
Replies
  • Currently Being Moderated
    Feb 27, 2013 1:16 PM   in reply to redtopia-dev

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 18, 2013 5:55 PM   in reply to redtopia-dev

    Redtopia-dev - I've updated the bug base bug but will re-iterate my workaround here.

     

    I was able to kludge a fix by wrapping the content of the 404 handler using CFSaveContent then forcibly writing the content length:-

     

        <cfsavecontent variable="thePage">

        Your 404 code here

        </cfsavecontent>

        <cfcontent reset="Yes" type="text/html"><cfheader name="Content-Length" value="#len(thePage)#"><cfoutput>#thePage#</cfoutput><cfabort>

     

    Note: I have the cfcontent through to the cfabort on one line so there's no additional whitespace.

     

    CF9 doesn't seem to set a content length header but it doesn't seem to make a difference.. CF10 however ... Tomcat must not be adding the magic ingredient at the end of the CF handling and passing it back to IIS.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2013 1:46 PM   in reply to redtopia-dev

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2013 11:29 AM   in reply to martypaz

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 30, 2013 12:12 PM   in reply to lars@work

    The latest ColdFusion 10 Update 11 seems to have addressed this bug finally:  http://helpx.adobe.com/coldfusion/kb/coldfusion-10-update-11.html

     

    I have not tested though, since my  workaround mentioned above works for me.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2013 1:24 PM   in reply to lars@work

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2013 1:58 PM   in reply to lars@work

    Hi

     

    Check the article for Verbose logging : http://helpx.adobe.com/coldfusion/kb/enable-verbose-logging-coldfusion -10.html

     

    NOTE : Enable Verbose strictly during maintenance.

     

    Delete the isapi_redirect.log. Enable the verbose log ( level=debug) and then hit any of the non -existing .cfm page in your application and then you will get custom 404 error (may be not, may be truncated, may be entire page). Then change the level = info.

     

    Provide the verbose log

     

    Thanks

    VJ

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2013 10:57 AM   in reply to lars@work

    Hi Lars,

     

    Did you try reinstalling the IIS connector as suggested here? http://blogs.coldfusion.com/post.cfm/coldfusion-10-does-the-connector- need-to-be-re-installed-for-update-11

     

    Just installing update 11 is not enough apparently.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 17, 2013 7:21 PM   in reply to henrylearn2rock

    hi guys,

     

    I solved this by going into IIS, and the error pages menu, and selecting detailed error pages. hope that helps?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 17, 2013 7:31 PM   in reply to rezengine

    While you will see more detailed diagnostics from IIS by selecting "detailed error pages" you will still not be able to use custom ColdFusion handler files unless you implement <httpErrors existingResponse="PassThrough" /> in your web.config and/or a combination of other things mentioned above.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points