address check

Discussion in 'ASP .Net' started by Bert, Dec 17, 2006.

  1. Bert

    Bert Guest

    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
     
    Bert, Dec 17, 2006
    #1
    1. Advertising

  2. Bert

    Mark Rae Guest

    "Bert" <> wrote in message
    news:...

    > 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...
     
    Mark Rae, Dec 17, 2006
    #2
    1. Advertising

  3. Try this (from
    http://geekswithblogs.net/azamsharp/archive/2006/06/08/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" <> wrote in message
    news:...
    > 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
    >
     
    Eliyahu Goldin, Dec 17, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avnrao
    Replies:
    1
    Views:
    7,273
    avnrao
    May 4, 2004
  2. Patrice
    Replies:
    0
    Views:
    905
    Patrice
    May 4, 2004
  3. Raterus
    Replies:
    0
    Views:
    451
    Raterus
    Jun 2, 2004
  4. Alex Stevens
    Replies:
    0
    Views:
    789
    Alex Stevens
    Aug 10, 2004
  5. =?Utf-8?B?QW5nZWw=?=

    Pass a Web Address and return a File System Address

    =?Utf-8?B?QW5nZWw=?=, Sep 20, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    550
    =?Utf-8?B?U3RldmUgQy4gT3Jy?=
    Sep 21, 2005
Loading...

Share This Page