Shaun Mccran

My digital playground
 
02
M
A
R
2010

Changing the 404 template handler in IIS

You could use a 404 ColdFusion template to handle missing templates, or the onmissingtemplate Application CFC function. Luckily I have a client with half a dozen sites all on the same server, with nothing else on it, so it makes more sense to do this in Internet Information Services.

404 templates are a handy way of masking any site errors or missing templates. Not only are they a cosmetic fix to nasty display errors but they can also seriously help your server security.

A recent incident where I was helping a friend setup a custom tag path on his server demonstrated this. He couldn't remember where the webroot was to point ColdFusion server at his custom tags directory. The default IIS 404 message will quite happily serve up a template telling anyone who cares to look where your webroot is, and half the other details of your server.

Begin by opening the IIS management console. Expand the list of websites in the left-hand pane of the console, and right-click on the icon for the website you want to customize. Choose "Properties" from the popup menu, and click the "Custom Errors" tab in the configuration window.

IIS screenshot

Enter the URL for the error template. At this point I was getting an error message "The path is not a local absolute path". The error is that windows is looking for a UNC path, so it needs a proceeding forward slash.

Specify a 404 location

A few points to note in your custom 404 templates.

  • Keep it simple. It isn't part of your site, its an error handler and should not really feature any functionality.
  • 404 might mean something to us, but it probably wont to most users. Is there really any reason to display 404 all over the page?
  • The url will be relative from where the error was thrown so hard code any url values used. IE CSS images or links to anywhere.
  • Add logging. Either Google Analytics tracking, or what ever tracker you use. I also like to drop a cfmail request in there so that I know its gone wrong.

TweetBacks
Comments

This content is purely my opinon, any offence or errors are unintentional, please comment your views appropriately
Site Credits
Aggregated by ColdfusionBloggers.org Powered by Coldfusion

Technology & Science Blogs - BlogCatalog Blog Directory Blog Directory & Search engine