Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   address check (http://www.velocityreviews.com/forums/t384048-address-check.html)

Bert 12-17-2006 11:27 AM

address check
 
Hi

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

thanks

B



Mark Rae 12-17-2006 12:15 PM

Re: address check
 
"Bert" <beffer@gmail.com> wrote in message
news:OHK5f5cIHHA.4992@TK2MSFTNGP04.phx.gbl...

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



Eliyahu Goldin 12-17-2006 12:20 PM

Re: address check
 
Try this (from
http://geekswithblogs.net/azamsharp/...8/81251.aspx):

private bool DoesUrlExists(string url)
{
bool urlExists = false;
WebRequest req = WebRequest.Create(url);

try
{
HttpWebResponse response = (HttpWebResponse) req.GetResponse();
urlExists = true;
}
catch (System.Net.WebException ex)
{

}

return urlExists;
}


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


"Bert" <beffer@gmail.com> wrote in message
news:OHK5f5cIHHA.4992@TK2MSFTNGP04.phx.gbl...
> Hi
>
> 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
>
> thanks
>
> B
>





All times are GMT. The time now is 06:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.