In order to allows ColdFusion showing its errors instead of just server error (code 500), I have added to web.config according to some findings in this site.
The problem looks resolved but...
When I visit a non-existed directory in the IIS, it returned a "blank" page without any status code. If I set it from passthrough back to auto, the IIS takes the error page again and no more ColdFusion errors showed.
Anyone has a solution? I did some research and "suspect" that the JWildcardhandler maybe the problem, but I couldn't find a solution to this.
Much appreciated!
In case anyone is wondering this person's web config probably looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors existingResponse="PassThrough" />
...
</system.webServer>
</configuration>
In earlier version of IIS, if your custom script returned an error code, IIS ignored it and let it through. But you could also set it up to handle error status with custom scripts.
On my old server, if a given URL was a 404, IIS was set up to execut /404.cfm, which displayed an error page and returned a 404 status code using <cfheader>
.
However, now if that script returns a 404 status code, the end result is IIS returns a server error rather than return the response with the 404 status code.
The only way to avoid that is by using existingResponse="PassThrough"
and then using a site-wide "Template Not Found" template, set in CFAdmin.
Here's the interesting part. I have index.cfm set up as the default index, and the only default index, for my site.
If I go to /about/
, and /about/index.cfm
exists, then it renders the page, as if I had asked it for /about/index.cfm
.
And if I go to /about/index.cfm
and /about/index.cfm
does not exist, it executes the site-wide 404 template.
But if I go to /about/
and /about/
does not exist as an URL, it does not attempt to load /about/index.cfm
and thus trigger the site-wide 404 template. Instead, it renders a blank page!
As far as I can tell, there is no workable solution to this problem. It looks like only people writing in .Net can resolve this issue, as they can put a flag in the Response that they generate that literally tells IIS "Ignore the status code". I think that Microsoft simply isn't interested in supporting alternate web application.
Basically, this is the solution:
get rid of existingResponse="PassThrough"
and return the wrong status codes.
Anything else is going to be too hard to implement. Note that this does not work if you are making a RESTful app or API. In which case, you must create a virtual directory just for that, for which you can assign a custom web.config file which does use existingResponse="PassThrough"
. But if you need to be able to allow custom error handling and custom 404 handling, you are effectively screwed.
The good news is, apart from API and Ajax, the only other time someone will care about what the status code actually is will be when they're looking at your headers anyway, in which case they will see you're running IIS and just feel sorry for you.
Keeping the passthrough in place, you could use a rewrite to handle the blank page:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.cfm [NC,L,NS]
The rewrite basically means - if file and directory do not exist, redirect to "404.cfm. Also include a 404 cfheader on the 404.cfm page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With