• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Jan 23, 2013 Jan 23, 2013

Copy link to clipboard

Copied

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?

TOPICS
Connector

Views

13.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 27, 2013 Feb 27, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2013 Feb 27, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 18, 2013 Mar 18, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 19, 2013 Mar 19, 2013

Copy link to clipboard

Copied

I was able to verify that this does work for non-ColdFusion files when used in conjunction with <cfheader statuscode="404" statustext="Not Found">. I verified that the entire document content is returned to the browser, and a status code of 404 is returned.

However, I cannot get this to work for ColdFusion files going through the onMissingTemplate method inside Application.cfc. Inside onMissingTemplate, when I call <cfheader statuscode="404" statustext="Not Found">, something is preventing content from being sent back in the request, and I get a statuscode of 200. My response header looks like this:

HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 X-Powered-By: ASP.NET Date: Tue, 19 Mar 2013 16:36:09 GMT Content-Length: 0

When I remove <cfheader statuscode="404" statustext="Not Found">, everything works - but I get a statuscode of 200.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 22, 2013 May 22, 2013

Copy link to clipboard

Copied

Looks like the bug has been fixed, but there's no mention on how to get the update yet.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 30, 2013 Jul 30, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 30, 2013 Jul 30, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 12, 2013 Aug 12, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 12, 2013 Aug 12, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 15, 2013 Aug 15, 2013

Copy link to clipboard

Copied

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

Just installing update 11 is not enough apparently.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 17, 2013 Sep 17, 2013

Copy link to clipboard

Copied

hi guys,

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 17, 2013 Sep 17, 2013

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 17, 2013 Sep 17, 2013

Copy link to clipboard

Copied

That didn't solve it for me. Turning on detailed error pages for a 404 error (that is not a CF file) will cause an IIS detailed error page to show.

My workaround is this (404.cfm)

<cfsetting enableCFoutputOnly="true">

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

<cfheader name="Connection" value="Close">

<cfsavecontent variable="errorPage">

<cfoutput>

<p>Put your error page in here</p>

</cfoutput>

</cfsavecontent>

<cfcontent reset="Yes" type="text/html">

<cfheader name="Content-Length" value="#Len(errorPage)#">

<cfoutput>#errorPage#</cfoutput>

You can also refer to the StackOverflow page for this bug:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 22, 2014 May 22, 2014

Copy link to clipboard

Copied

rezengine wrote:

hi guys,

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

I verified this on CF 10 running on Windows Server 2012 R2.   rezengine's suggestion above worked for me.  I was seeing the detailed error message from within IE 11 (Internet Explorer 11) on the server, but not from any workstation.

1. Go into IIS.

2. Select the website from the tree on the left that you wish to modify.

3. Double-click the "Error Pages" Icon from the window pane to the right.

4. Click ONCE to highlight the Status Code 500.

6. Click "Edit Feature Settings..." to the right of the right window pane in the side bar.

7. Change the setting from "Detailed errors for local requests and custom error pages for remote requests" to "Detailed errors" then click the OK to save.

8. Do this for any other Status Code you wish to see error messages.

Hope this helps.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2014 May 23, 2014

Copy link to clipboard

Copied

As for redtopia-dev above, on CF10 with IIS8, the only way we can get 404 errors to work across all scenarios (non .cfm file extensions, e.g. .html, non-existent folders, non-existent .cfm's etc) is by making IIS use the "Execute URL" setting in Error Pages to our custom /404.cfm template, and then in that template put this code right at the bottom of the template (last 2 lines)

<cfheader statusCode="404" statusText="Not Found">

<cfheader name="Connection" value="Close">

Unless we do that, no combination of code and/or settings in IIS will make 404's work across all scenarios. We have tried every combination. Most annoying; this issue (bug) has existed for years. Can Adobe please give a definitive way of making IIS8/CF10 custom 404's work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 23, 2014 May 23, 2014

Copy link to clipboard

Copied

Hi All,

You may like to have a look at https://bugbase.adobe.com/index.cfm?event=bug&id=3488063 notes. The issue is fixed and the patch is available.

Regards,

Anit Kumar

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2014 May 23, 2014

Copy link to clipboard

Copied

Anit, where's the patch download? We are on the all updates except #13.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 23, 2014 May 23, 2014

Copy link to clipboard

Copied

This is not included in the ColdFusion updates. Send an email to cfinstal<AT>adobe<DOT>com, referencing this thread for Bug#3488063.

We will share the fix with you.

Regards,

Anit Kumar

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 02, 2014 Jun 02, 2014

Copy link to clipboard

Copied

LATEST

tribule,

This works for us as well; we tried some of the other options even the with update 13 this was the only way we could get the custom 404.cfm page top load every time.

Shawn

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation