I have a ASP.Net 3.5 Web app (C#) where I need to programmatically check to see if another one of our sites (that isn't ASP.Net) is up and running. Currently, I have a method with the following code which checks for a StatusCode of 200. The issue I'm running into is that the IIS7 splash page that comes up returns a status code of 200, and I don't see anything else within the response object that would allow me to verify the page we are expecting actually displays. I would like to avoid getting the response back and using a StreamReader just to look for a div on the page to verify it's valid (if possible) as they do (similarly) in this link.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlToCheck);
request.AllowAutoRedirect = true;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
return true;
}
return false;
}
catch (Exception)
{
return false;
}
Any help is greatly appreciated.