Using MMC change the default 404 (htm) page to use an asp script. Be sure NOT to use the browse feature, but instead select the URL option. (If URL option is not used, the server will not process the script and return the document directly to the client). The custom 404 Error can be set at any directory level, and will be executed whenever an invalid request is made to that directory (or sub-directory).
The custom 404 script would evaluate the ServerVariables("QUERY_STRING") variable to retrieve the invalid URL. Then the invalid URL would be parsed for variables to query the database and return the proper results. The dynamic page could be displayed directly through the 404 script, or even leverage the new IIS 5.0 Server.Transfer or Server.Execute methods which retain session state and session variables (but don't allow query strings).
We tell IIS not to look for the file, but rather to pass the request directly to CF. CF let's you assign a single template to handle 404s and since CF doesn't know where anything is, all requests on the server go through that template.This controller template first figures out what domain it's dealing with and what files are needed to handle requests on that domain. It then passes the requests along. Each domain has its own set of apps to interpret incoming requests and generate pages. Then CF says "here you go" and passes the code along to IIS and on to the browser.
We do it pretty much the same way in Apache, but I think Apache checks for the file before passing it off to CF. This is okay, but Apache includes a 404 header. IE has some friendly error message mumbo jumbo that will read the 404 header and ignore the code served (serves a friendly 404 rather the page). To fix this we use <cfheader statuscode="200" statustext="OK"> in the Missing Template Handler to write over the HTTP Status header on the way back to the browser.
Both are great guys who helped me create our 404 trap in ASP!~