Okay, so it took quite a while to work this one out but it got there eventually. For the sake of anyone looking to do the same thing, here's what I found:
Even if the server is down if you create a new XmlHttpExecutor (or any other executor for a webrequest) and invoke it or execute it to get the current website, you will get a response (which I'd guess is almost certainly a cached version of the page since the server can't be returning it). This makes it very difficult to use javascript to determine whether the website has come back up. The way I got around this was to create a simple hello world webservice on the site and use Ajax to retrieve the Hello world string - this method does fail reliably (helps that you can't realistically cache a webservice response) so you can use that to determine whether the service is running.
Of course, while access to the page isn't available any post back calls from existing controls would cause another error to be thrown, so I overrided the postback function with a bypass variable that checks if the page has gone into a non-communicative state. Anyway - code is below for anyone that requires it (don't forget you need to register any web services in the script manager and as web references once you're done).
<script type="text/javascript" src="Namespace.js"></script>
<script type="text/javascript" language="JavaScript">
var webserverCheckDelay = 5000;
var oldPostBack
// Override postback function to allow a bypass when
// communication goes down (prevents unexpected autopostbacks throwing an error
var isFunctioning = true;
function window.onload()
{
oldPostBack = __doPostBack;
__doPostBack = MyFuntion;
}
function MyFuntion(eventTarget, eventArgument)
{
if (isFunctioning)
{
oldPostBack(eventTarget, eventArgument);
}
}
// Add handler to pick up communication errors
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args)
{
if (args.get_error() != undefined)
{
if ((args.get_response().get_statusCode() == '12007') || (args.get_response().get_statusCode() == '12029'))
{
isFunctioning = false;
//Show a Message like 'Please make sure you are connected to internet';
args.set_errorHandled(true);
document.body.innerHTML = "";
document.body.innerHTML += "<table class=\"wallboardLayoutTable\" cellpadding=\"0\" cellspacing=\"0\">";
document.body.innerHTML += "<tr><td class=\"wallboardLayoutLeftMarginCell\"> \</td>";
document.body.innerHTML += "<td class=\"wallboardLayoutMainContentCell\">";
document.body.innerHTML += "<span style=\"font-size: 44pt; color: Red;\"><p align=\"center\">Communication with the server has been lost - please check network connectivity</p></span>"
document.body.innerHTML += "</td></tr><tr><td class=\"wallboardLayoutBottomMarginCell\" colspan=\"2\"> </td></tr></table>";
// Start the delayed calls to try and find the server
setTimeout("RepeatedRefreshRequest()", webserverCheckDelay);
}
}
}
// Call the webservice to check for a response from the server
function RepeatedRefreshRequest()
{
CmsWallboard.IsAliveService.IsAlive(webserviceReturn, webserviceFailure);
}
// If webservice call fails, check again after a delay
function webserviceFailure(exception, userContext, methodName)
{
setTimeout("RepeatedRefreshRequest()", webserverCheckDelay);
}
// On success, reload the page (accept a page flash to get a clean load after the server is restored)
function webserviceReturn(result, userContext, methodName)
{
if(result.toString() == "Server is alive")
{
location.reload(true);
}
else
{
setTimeout("RepeatedRefreshRequest()", webserverCheckDelay);
}
}
</script>
Obviously I used some code samples from the web to help me along since I'm quite new to this - http://dotnetslackers.com/columns/ajax/ASPNETAjaxWebService.aspx and http://weblogs.asp.net/sbehera/archive/2005/08/04/421578.aspx were useful