An easy way to ping a web server to make sure it is working / alive?

I have a distributed website (.NET, IIS) with a dynamic number of servers around the world.

I want to create a [simple] utility that will be hosted in our home location, and every time "ping" the web servers to find out if they work. I will then record this result for each server in the database to show the current status and history of any detected downtime.

What is the best way to do this? Connect via HTTP from .NET? I want this not to be much code (ideally) and run as a service.

Any links or code examples are welcome.

Is this standard practice? Or do distributed applications usually do something else? (e.g. home phone, not ping).

+3
source share
2 answers

Here is an SO question that is close to yours:

Best way to check if a site is alive using C # application

Basically, you can check the status of a website using the following code:

WebRequest request = WebRequest.Create("http://localhost/myContentSite/test.aspx");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
   Console.WriteLine("You have a problem");
}

, -, . , . . , , - ( ), , . , . , - , , , " ". , .. , , .

+3

WebRequest.

var request = WebRequest.Create("http://google.com");
using (var response = request.GetResponse())
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
    var responseText = streamReader.ReadToEnd();

    // validate that responseText has content that you would expect
}

, , . - StatusCode HttpStatusCode.OK, IIS , , .

0

All Articles