3

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

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
Redtopia
  • 4,947
  • 7
  • 45
  • 68
  • I'm seeing this exact same issue, and haven't had a resolution yet. – Dan Short Mar 04 '13 at 13:28
  • Have you voted for the bug I submitted? If not, I encourage you to do so. https://bugbase.adobe.com/index.cfm?event=bug&id=3488063 – Redtopia Mar 04 '13 at 17:13
  • I'm seeing other 404 related issues, which I posted about here (http://stackoverflow.com/questions/15202458/404-handler-hanging-on-coldfusion-10-works-perfect-on-coldfusion-8). I don't if you're seeing the same thing or not. – Dan Short Mar 04 '13 at 18:53

5 Answers5

4

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.

charlie arehart
  • 6,590
  • 3
  • 27
  • 25
  • Thanks... I did the update and the problem persists. I will try to update the connectors for IIS and see what happens. – Redtopia Jul 22 '13 at 18:27
  • The update is definitely not working for me. I removed and reinstalled the connector (for all web sites) and I get serious inconsistencies in behavior. In most cases, I get a connection reset error (Firefox) and Chrome says "This website is unavailable". I have one web site where it does work, but intermittently. – Redtopia Jul 22 '13 at 20:28
  • It appears that several people are reporting that the problem is not fixed. I sent CF some log files as they requested. I encourage people to report their findings to the bug database: bugbase.adobe.com/index.cfm?event=bug&id=3488063 – Redtopia Jul 29 '13 at 18:32
  • The bug was not fixed in the update and has since been re-opened as of Sept. 2013. – Redtopia Sep 16 '13 at 17:13
1

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.

Martin Parry
  • 319
  • 2
  • 5
  • This does work for non-ColdFusion files... adding into your workaround does return both content and the 404 statuscode. I haven't been able to get it to work for ColdFusion files... even if I remove the onMissingTemplate method inside Application.cfm. When I do use the onMissingTemplate method and I call , no content is returned. When I remove it, content is returned along with a statuscode of 200. – Redtopia Mar 19 '13 at 16:47
0

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.

  • My first thought is this... the goal is to output the error page AND the 404 error. This solution will redirect to an error page but the resulting page will not include the 404 error code, which might have implications with crawlers. Not sure though. – Redtopia Aug 05 '13 at 19:16
0

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).

Redtopia
  • 4,947
  • 7
  • 45
  • 68
  • 1
    For more information about the missing requested file name see this - [ColdFusion 10 + IIS: Non-existant URLs that are CFM files. Retrieving original URL after executing 404 page](http://stackoverflow.com/q/18694932/1636917) – Miguel-F Sep 16 '13 at 16:52
  • I looked at that thread and it seems like the only workaround is to install the Ionic IIS Redirector as a 3rd party ISAPI app. – Redtopia Sep 16 '13 at 17:12
  • I don't know if that is the only workaround but a couple of people have done that. Did you notice that they also entered a bug for this with Adobe. I am interested to see how they reply to that. If nothing else perhaps they can reply with their recommended configuration to retrieve the requested page. Vote for the bug if you haven't already - https://bugbase.adobe.com/index.cfm?event=bug&id=3630245. – Miguel-F Sep 16 '13 at 17:15
  • I'm not positive, but I don't think there are any duplicates of this bug in the CF bug database. I reported the bug, created this thread and I've been working with Adobe to help them figure it out. However, after working with them for the past month, I don't get the feeling that they've made much progress. There are quite a few posts in the bug DB itself, which is how I came up with this solution. I'm pretty sure this is high on their radar. – Redtopia Sep 17 '13 at 02:26
0

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.