Firstly, Irequest and Iresponse should not be called that way. They should be webRequest and webResponse , or even just request and response . The capital prefix "I" is usually used only for the interface name, and not for variable variables.
To validate URLs, use UriBuilder to get Uri . Then you should use HttpWebRequest and HttpWebResponse so that you can check the response to the typed status code. Finally, you should be a little more informative about what was broken.
Here are links to some of the additional .NET materials that I submitted:
Example:
try { if (!string.IsNullOrEmpty(url)) { UriBuilder uriBuilder = new UriBuilder(url); HttpWebRequest request = HttpWebRequest.Create(uriBuilder.Uri); HttpWebResponse response = request.GetResponse(); if (response.StatusCode == HttpStatusCode.NotFound) { _txbl.Text = "Broken - 404 Not Found"; } if (response.StatusCode == HttpStatusCode.OK) { _txbl.Text = "URL appears to be good."; } else //There are a lot of other status codes you could check for... { _txbl.Text = string.Format("URL might be ok. Status: {0}.", response.StatusCode.ToString()); } } } catch (Exception ex) { _txbl.Text = string.Format("Broken- Other error: {0}", ex.Message); }
source share