Sunday, 13 January 2013 13:55

how to monitor website

Written by 
Rate this item
(0 votes)

It is needed to check whether your website is
available or down.It's better you create a WPF
application to check that.you can also check
status periodically besides checking status on
a button click.the following program shows how
to check the website status by clicking a button -

when the check button clicked the method
shows the status of the website in a ListBox as
a ListBox item -

private void buttonCheckNow_Click(object sender, RoutedEventArgs e)
{
string website = null;
website = "http://www.csharpersworld.com";
if (ConnectionAvailable(website))
{
listBoxStatus.Items.Add("Status OK " + website + " " + DateTime.Now.ToShortTimeString());
}else{
listBoxStatus.Items.Add("Status FAILED " + website + " " + DateTime.Now.ToShortTimeString());
}}

the method -

public bool ConnectionAvailable(string WebSiteString)
{
try
{
HttpWebRequest reqFP = (HttpWebRequest)HttpWebRequest.Create(WebSiteString);
HttpWebResponse rspFP = (HttpWebResponse)reqFP.GetResponse();
if (HttpStatusCode.OK == rspFP.StatusCode)
{
// HTTP = 200 connection available, server online
rspFP.Close();
return true;
}else
{
// Other status - Server,connection not ok
rspFP.Close();
return false;
}}
catch (WebException)
{
// Exception - connection not available
return false;
}}

Read 2777 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.