3
votes

I'm having difficulties handling 404 errors correctly in ColdFusion 10 on Windows 2008 R2 x64 using a custom error handler (Execute URL) in IIS. I've done this in previous versions of CF with no problems. In IIS, under the web site features, I open "Error Pages" and set it to execute "/404.cfm" for all 404 errors.

The problem I'm having is that the output of the 404.cfm page is not completely being sent back to the browser and the page doesn't load correctly. Sometimes I get nothing back, other times I get 1K, other times I get a little bit more. It's very inconsistent.

Along with setting the 404.cfm handler in IIS, I am also calling it in the onMissingTemplate() method inside Application.cfm:

<cffunction name="onMissingTemplate"
    returnType="boolean"
    output="true">

    <cfargument name="thePage" type="string" required="true">

    <cftry>

        <cfmodule template="../../../404.cfm" thePage="#Arguments.thePage#">

        <cfcatch>
            <cfoutput><p>An error occurred</p></cfoutput>
        </cfcatch>

    </cftry>

    <cfreturn true />
</cffunction>

Inside my 404.cfm error handler, I'm calling:

<cfheader statuscode="404" statustext="Not Found">

... and then I output a bunch of stuff.

When I remove the call to cfheader in 404.cfm, the error handler loads correctly [for ColdFusion requests]. That's because nothing is going through IIS - instead, it's simply going through the onMissingTemplate() method in ColdFusion. However, the response header gives me a 200 status code, which is a problem! It needs to be a 404 status code for obvious reasons.

When I include the cfheader call, OR when a non-ColdFusion page is being requested (IIS will generate the 404 status code), the output of my 404.cfm handler is not completely returned to the browser. I think has something to do with IIS getting its hands on the action.

I did report this in the CF bug database, but I'm wondering if there's something I'm doing wrong. The bug is here: https://bugbase.adobe.com/index.cfm?event=bug&id=3488063

5
I'm seeing this exact same issue, and haven't had a resolution yet.Dan Short
Have you voted for the bug I submitted? If not, I encourage you to do so. bugbase.adobe.com/index.cfm?event=bug&id=3488063Redtopia
I'm seeing other 404 related issues, which I posted about here (stackoverflow.com/questions/15202458/…). I don't if you're seeing the same thing or not.Dan Short

5 Answers

4
votes

This bug is indeed finally fixed for CF10, with update 11. See http://blogs.coldfusion.com/post.cfm/coldfusion-10-update-11-an-update-with-50-fixes. It only mentions it in passing ("8. Web Container/Tomcat - CGI.server_port, IIS custom error handlers"), but it is there.

And the bug report referenced above has also been updated to indicate that it's fixed with this update.

But let me offer a word of warning: some folks are saying (at the bug report) that they are finding the problem NOT fixed even after applying the update.

There's a very likely explanation: please note that after applying update 11, you MUST either update or rebuild the web connector for IIS. For more on that, see http://blogs.coldfusion.com/post.cfm/coldfusion-10-does-the-connector-need-to-be-re-installed-for-update-11.

More specifically, if you look at the coldfusion10\config\wsconfig[nn\ folder (where nn is a number, of which folders you have more than one), and your isapi_redirect.dll is not dated in May 2013, then you have NOT yet done the needed update 11 and will still seem to have the problem.

And be sure to update all of your connectors, if you have more than one such folder under wsconfig. If after doing that, and restarting IIS perhaps, if you are still having the problem, then do report back at the bug report confirming that. Perhaps there may be something else to explain it, but we'd want to rule this issue out first.

1
votes

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.

0
votes

I have not found update 11 to work. Even after connector updates. Another kludgey fix:

<CFPARAM default="0" name="URL.r">
<CFPARAM default="0" name="URL.t">
<CFSET ErrUrl = "/cfm/global/404error.cfm">
<CFIF URL.r IS 0>
<CFIF FindNoCase( ".htm", CGI.HTTP_REFERER ) GT 0>
    <CFLOCATION url="#ErrUrl#?r=1&t=htm">
</CFIF>
<CFIF FindNoCase( ".cfm", CGI.HTTP_REFERER ) GT 0>
    <CFLOCATION url="#ErrUrl#?r=1&t=cfm">
</CFIF>
    <CFLOCATION url="#ErrUrl#?r=1"> 
</CFIF>
<CFIF URL.t IS "htm">
    <CFHEADER statuscode="404" statustext="Page Not Found">
</CFIF>

placed at the top of your error page (change your ErrUrl to point to your error page) works for both CFM and HTM(L) pages. It's gross, but seems to work.

0
votes

Inside my 404 handler, I added:

<cfheader statuscode="404" statustext="Not Found">
<cfheader name="Connection" value="Close"> <!--- this is the fix! --->

Closing the connection seems to work for some reason.

And to output the page, I'm doing:

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

... where the variable fullpage is the content of the 404 handler.

Now I can now consistently return both a 404 status code error AND the entire contents of my error page. However, when a non-ColdFusion page is requested, the CGI values are not correct. Prior to CF10, I could get the requested page by looking at the CGI parameters, specifically CGI.query_string, which used to look like: “404;http://www.example.com/some/file.html” Now I’m getting: “404;http://www.example.com/jakarta/isapi_redirect.dll”, which makes it impossible to get the requested page.

However, the fact that I can now return an entire document makes this at least a partial workaround to the bug, which is still open (after over a year of CF10 being released)! For now, instead of trying to figure out what page was requested and looking at my sitemap, I'm simply outputting a standard "page not found" error.

I should also mention that I'm using the same 404 handler in the onMissingTemplate method in Application.cfc. The requested page is passed into this method, which I then pass to my 404 handler in the Attribute scope, and I call my 404 handler as a cfmodule. So this is a complete solution when it's a ColdFusion page being requested, and only a partial solution when a non-CF page is requested (since we can't determine the requested file).

0
votes

fix i came up with after trial and error is in the custom404.cfm that you have pathed to in iis7 put the following code

<cfinclude template="/inc_mypathtoroot/my404.cfm">
<cfheader name="Connection" value="Close"> 

then create the file my404.cfm in the root (the path for the include will need to be your include path)

in the my404.cfm file put your processing code. BUT DO NOT USE <CFABORT> ANYWHERE IN THAT FILE AS IT WILL CAUSE THE CONNECTION TO BE RESET.