Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: .NET
Expertise: Advanced
Jul 2, 2007

Determine Whether a URL Is Valid

Use this Boolean function to determine whether a URL is valid:

public static bool checkUrl(string url) 
{
  bool rt = false;
  if (url.StartsWith("www."))
  {
   url = "http://" + url;
  }
  HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url); 
  HttpStatusCode code = new HttpStatusCode(); 
  HttpWebResponse myResponse = null; 
  try
  { 
   myResponse = (HttpWebResponse)myRequest.GetResponse();
   code = myResponse.StatusCode;
   rt = true;
  }
  catch(WebException err)
  {
   rt = false;
  } 
  return rt;
}
Srinath MS
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap