Determine if a page is up or down.

  • Thread starter Thread starter Chris Carter
  • Start date Start date
C

Chris Carter

We have a site, for reference I'll call this MainSite,
that has certain pages actually hosted on another site,
I'll call this ChildSite. In MainSite when you click on a
certain link, it loads a page with an IFrame that points
to a page in ChildSite. MainSite and ChildSite are on two
different machines. If MainSite can "see" ChildSite,
everything works like a champ. However, if there is a
network problem, firewall issue, or something else wrong
with "seeing" the ChildSite, the users in MainSite get
an "Action Cancelled" error. It's totally confusing to
receive that error and we're trying to come up with a way
around it.

What I want to do is check the availability of that page
in ChildSite before the IFrame starts its request. I have
some code that works fine under good conditions, here's
the basic concept:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create
(url);
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Console.WriteLine(response.StatusCode);

....basically i want to check and see if the response
status is OK(aka 200). My concern is this, usually if
there is a connectivity problem, the page will sit there
for up to 15 seconds before it displays a message
indicating the problem. If the page is up, it will
display in maybe one second, it's a very lite page with
very little to display or process. I need to know if I
should load up a worker thread to test for the web page
status, and then in a watcher thread, determine if after
say 2 seconds, if i haven't received an OK status, that
it's safe to say the page is down so kill the worker
thread. Or, can I rely on the HttpWebRequest to return a
status quickly enough to determine page status?

Or does anyone have a different but reliable solution for
checking the status of a web page?
 
you approach will work for most cases, but only if connectivity is down
between your site and the child site. it may be down for the user to child,
but ok for your site. you don't need a seperate thread, unless you just want
to poll and set a status, just reduce the timeout. polling would lead to
false ok's just when the site goes down.

another common approach is for your main site could proxy the child site.
your site translates the url to a local site and fetches the pages. you can
do this with a filter.

-- bruce (sqlwork.com)
 
Thanks for the response Bruce, I'll look into the proxy
suggestion. I like the idea of just testing whether the
main site can see the child site by getting back an OK
status. It's really just to shorten the timeout like you
mentioned and possibly give us a chance to throw up a
slightly friendlier "home grown" error page that makes it
_look_ like we have everything covered. Thanks again.
-chris
 
Back
Top