address check

M

Mark Rae

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top