As some of you may or may not noticed, my site was down earlier for maintenance (more on that later). None of the ColdFusion pages on my site were available, no matter what URLs you used. Creating a page like this is insanely easy when you are using ColdFusion's Application.cfc component. If you have ever examined the application event methods available in the Application.cfc, you will notice that several of them return a boolean value. This value, while tiny, plays a huge part in the page processing. Anytime that one of the event methods returns false, it kills the rest of the page / application processing.
Using this information, we can easily build our "Down For Maintenance" page directly into the architecture of the Application.cfc component. Since we want to display this page for every request, it feels natural to put this functionality in the OnRequestStart() event method:
Launch code in new window » Download code as text file »
When creating a Down For Maintenance page, we have to be concerned with more than just the visual aspects; we also want to make sure that search engines such as Google and Yahoo respect that fact that our site is down and don't just assume that our site no longer has content! To do this, we explicitly set the Status Code of the page header to be:
503 - Service Temporarily Unavailable
This will alert the search engine bots and spiders that the site is down and to ignore the pages. But, we also want to take it one step further - we want to reassure the search engine bots that the site will be back up and that the bots should re-index the site shortly. To do this, we set another header value, retry-after. This returns the number of seconds (3,600 in our case) the search engine bots should wait before trying to re-index the site. While I am not sure about this, I have read that if you do NOT return a retry-after header value, the client (browser / bot) should treat this as a 500 - Internal Server Error, so be sure to set this properly!
After our header values, we output our HTML content and then return false. Returning "false" here is a huge point because by returning false, the ColdFusion application server knows not to even bother calling the OnRequest() event method which would have processed the requested template.
If you are using ColdFusion's Application.cfm template instead of Application.cfc, the same thing can be done, but with slightly less elegance. Instead of using any event methods (which don't exist in Application.cfc), you could simply put the header and output code directly into the Applicaiton.cfm:
Launch code in new window » Download code as text file »
Then, instead of returning false, simply stop the page processing by executing a ColdFusion CFAbort tag.
While we put our output and header logic directly into our Application templates, there is nothing to say that we couldn't wrap this functionality into a template of its own which could then be included in the Application templates.
Download Code Snippet ZIP File
Comments (8) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
Just testing to make sure this works.
Posted by Ben Nadel on Jan 9, 2008 at 3:30 PM
Your site kept coming up in my google search for an cfajaxproxy issue I was running into and YOU WERE NOT THERE FOR ME! :( :(
;)
Posted by Todd Rafferty on Jan 9, 2008 at 4:30 PM
@Todd,
Switching some name server stuff and it's causing a huge hassle. Never done this before, so trying to figure out how to get it done :)
I think by tomorrow, everything should be propagated and stuff will work smoothly going forward.
Posted by Ben Nadel on Jan 9, 2008 at 5:08 PM
Yeah, DNS can be tricky. Running a split DNS server at home. Fun fun.
Posted by Todd Rafferty on Jan 9, 2008 at 5:12 PM
This is a nice method, but I prefer to do it at the webserver level, as this obviously only works for coldfusion pages. Just create a second website that points to a page with the Maintenance message (use the 404 handler to do this too), set it up with all the same domains as the original site, stop the original site and start the second site.
Assuming you have access to the webserver.
Posted by duncan on Jan 10, 2008 at 12:10 PM
@Duncan,
Yeah. I am only recently getting more access to the server / IIS, so until then, this would have been my only option (without having to talk to management).
One of the things that I like about the ColdFusion method is that you can easily put in some logic to allow access from certain IP addresses. I am sure that you can do this via IIS, but I don't know how off-hand.
Posted by Ben Nadel on Jan 10, 2008 at 2:36 PM
You can also do this in the onRequest method. If you use on request, you can, by default, include the #targetPage# to have it function normally. Then, if you need to repoint, just change the include to the sorry page.
Same idea, different method.
Posted by lincoln on Jan 10, 2008 at 3:37 PM
@Lincoln,
Absolutely. That probably has the cleaner set of code, as well.
Posted by Ben Nadel on Jan 10, 2008 at 3:42 PM