blah blah blah is here! blah blah » Close

up0down
link

i am also trying for checking whether a URL is active or dead, so if u can post the replies.

last answered 9 months ago

1 answers

up0down
link

protected void Page_Load(object sender, EventArgs e)
{
string URL = "http://www.yahoo.com";
//Create a request for the URL.
WebRequest request=WebRequest.Create(URL);
request.Proxy=null;
//Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Display the status.
Response.Write(response.StatusDescription);
if (response.StatusDescription=="OK")
{
Response.Write("\n Site Exists.");
}
else
{
Response.Write("Does Not Exists.");
}
}

up0down
link

protected void Page_Load(object sender, EventArgs e)
{
string URL = "http://wwww.yahoo.com";
//Create a Webclient instance.
WebClient mywebclient = new WebClient();
//Download page data.
Response.Write("Downloading " + URL);
//Download the web resource and save it into a data buffer.
byte[] mydatabuffer = mywebclient.DownloadData(URL);
//Display the downloaded data.
string download = Encoding.ASCII.GetString(mydatabuffer);
Response.Write(download);
}
}

up0down
link

protected void Page_Load(object sender, EventArgs e)
{
string URL =@"http://www.yahoo.com";
//Create a request for the URL.
WebRequest request = WebRequest.Create(URL);
request.Proxy = null;
try
{
//Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Display the status.
Response.Write(response.StatusDescription);
Response.Write("\n Site Exists.");
}
catch (Exception exc)
{
Response.Write("\n Site does not exists.");
}
}

up0down
link

all depends of the return status code.
If the response status is 500, it means that the page is dead, it has an internal Server Error.

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback