ColdFusion Muse

Site by Site Missing File Handler in IIS

Mark Kruger September 7, 2006 2:29 PM Coldfusion MX 7, Coldfusion Tips and Techniques Comments (6)

Perhaps you've used my previous blog on IIS and missing file handlers to solve the problem of dynamically named folders or files. You might think that using the 404 handler in IIS in conjunction with your site wide missing template handler (set in the CFIDE Administrator) is your only option. What if you are on a shared server? Is there a way to implement a site by site missing template handler? Why yes Virginia there is.

The secret is to understand the sequence of how IIS and Coldfusion work together to handle a request. When IIS gets a request it uses the host header or IP address to find the correct site. At this point its job is to figure out which file or process to serve. Should it find a file on the disk or simply hand the request off to another process? When IIS sees a .cfm file it simply hands it to Coldfusion without even checking to see if its a legitimate template. Coldfusion must then figure out what to do with it. When the template doesn't exist, CF calls the "missing file handler" that is set up Coldfusion administrator. This handler applies to all Coldfusion sites on that server (or instance). That's where the problem lies. Multiple Coldfusion sites must all share the same missing file handler for CF requests. What is needed is a way to make IIS check to see if the file exists before it hands off to CF. That way it will call our carefully constructed CF 404 handler (see the previous post).

The Fix

This is actually possible (though not intuitive). These instructions are for Win2003, IIS 6. Go to IIS and open your site properties. Click on the "home directory" tab and then click on the configuration button. If you have a typical setup you should see the Jrun wildcard entry in the bottom list box. Select this entry and click on "edit". There is a checkbox that says "verify that file exists". You might think that this means that IIS is supposed to verify that the wildcard dll exists. Nope... it means for IIS to make sure and verify that the file referenced in the request actually exists before throwing it to the Jrun. Like I said, it's not intuitive. Select this check box and click ok. Under the hood, IIS will verify that a file exists before handing it off to Coldfusion. If it does not exist it will call your 404 handler. Viola'!! ... A site specific CF missing template handler. Not bad.

The Caveat

Sometimes CF handles requests for files that do not exist, but are still legitimate requests. It does this by maintaining a list of URL patterns that match servlet processes. For example, RDS depends on a pattern of /cfide/ide.cfm. When CF sees this pattern it knows what to do with the request. It invokes the RDS servlet. Now, however, IIS is going to intercept that request before it gets to CF. To fix it you will have to create an ide.cfm file and put it into a cfide directory - just to fool IIS. Once the request get's to CF it will know what to do. Other processes that might suffer from this same problem (I'm talking off the top of my head here - without testing) are charting, flash forms, and flash remoting.

  • Share:


  • Jason Holden's Gravatar
    Posted By
    Jason Holden | 9/7/06 1:12 PM
    We've setup our global missing template like this:

    <cfif CGI.SCRIPT_NAME EQ "/404.cfm">
             <h2>We're sorry - The page you are looking for does not exist.</h2>
             <p>If you continue to have this problem, please contact your administrator with the following information:</p>
             <p><a href="/">Click here</a> to return to the home page.</p>
       <cflocation url="/404.cfm" addtoken="no">

    So that we attempt to send the user to the 404 page in the site root, but if it's not available we then display the global error.
  • mark kruger's Gravatar
    Posted By
    mark kruger | 9/7/06 3:02 PM
    this is a test comment
  • Julian Halliwell's Gravatar
    Posted By
    Julian Halliwell | 9/8/06 2:32 AM
    Hi Mark,

    I use a similar approach to Jason, cflocating to a standardly named "404.html" file. Because the cflocation url is relative it will bring up the correct page for each individual site (assuming you need the message to be individualised and have created site-specific 404.html pages). To me the fact that CF only allows one missing template handler is an advantage: a single piece of code to deal with all sites. This seems a lot simpler/safer than messing with IIS and having to worry about "ide.cfm" etc.

    Cheers, Julian.
  • Ryan's Gravatar
    Posted By
    Ryan | 9/14/06 5:02 PM
    Yes, charting will be affected (on CF5 at least, don't know about later versions). You will need to create a /CFGraphingPage.cfm, just like was needed for /cfide/ide.cfm.
  • Toby Dawes's Gravatar
    Posted By
    Toby Dawes | 6/8/07 2:02 PM
    I tried this on XP Pro with IIS 5 and works great, but when implementing on Win2003 with IIS 6 it still throws the 404 to CF Admin, and idea why..???
  • Allen's Gravatar
    Posted By
    Allen | 12/10/09 3:31 PM
    Did you happen to figure this out, Toby? I'm having a similar issue with this in IIS7 which looks like they no longer have that checkbox.