tags:

views:

198

answers:

5

I'm thinking to add some code on the server side in asp.net, to verify if the website is working before redirect to it.

thanks.

A: 

Is there any particular reason for doing this? If there is a business reason then you probably don't have a choice.

In general this is a bad idea. The whole point of the internet is it's disconnectedness. There is no "guaranteed delivery".

With that said, you could when loading a page make a call to the other site by using "WebRequest and WebResponse" classes. Beware, if the other site is down this request will hang until timeout. Your users will experience this timeout with your page failing to load until the WebRequest to the other page has timed out. If this isn't implement carefully, the other site being down could make your site appear to be also down.

Chuck Conway
I need to redirect to the other site anyway, and sometimes it takes a long time to get response, so I think it maybe better to try it with a short timeout before redirecting...
Estelle
A: 

You can new up a HttpWebRequest and shoot off an HTTP "GET" and make sure the status code returned is 200.

Kevin Pang
A: 

Very naive and not particularly fast, but a start:

if ( new System.Net.WebClient().DownloadString(" url here ").Length > 0 )
{
   // ...
}
Joel Coehoorn
I think it will download the text anyway even if the website is not found. In that case the text will be "Website Not Found Error" or something
azamsharp
+2  A: 

you could do something like this:

System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(serverUrl);
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
    response.Close();
    return true;
}
ob
This is a bad idea. You are assuming the other site will respond. If it doesn't you will wait the default timeout. During this time loading of the page is being blocked by the WebRequest.
Chuck Conway
I think this is what I will do as a start, and set a timeout to to request. thanks.
Estelle
This is a bad idea, I say it too.
Andrei Rinea
A: 

You should fire up a thread in the start of the application that periodically checks for the availability of the site(s). Keep a Hashtable/Dictionary/whatver with information on this regard and query it when needed.

If any of you need specific details on how to do this comment on my answer.

Andrei Rinea