address check

  • Thread starter Thread starter Bert
  • Start date Start date
I am looking for a function in asp.net/vb.net to check a web address. I
want to check whether the url is really existing. For example
Function(http://www.prut.comm/ ) = false

Apologies that this is in C#, not VB.NET, but it should be easy enough to
convert:


using System.Net;
using System.Text;

string strURL = "http://www.prut.comm";
using (WebClient objWebClient = new WebClient())
{
using (StreamReader objStreamReader = new
StreamReader(objWebClient.OpenRead(strURL)))
{
// do nothing here unless you want to do more than just "ping" the
URL
}
}

If no response is received from the URL, the above code will generate a
System.Net.WebExeception with the message (in this particular case):
"The remote name could not be resolved: 'www.prut.comm'"

Surround the above with a try...catch and check explicitly for a
System.Net.WebException.

N.B. there may be more elegant ways of "pinging" a URL...
 
Back
Top