LemonAngel
New Member
Pinging Servers from .net. Is it possible. <BR><BR>Or can anyone suggest a good method for checking a URL exists when validating new links on my link directory.<BR><BR>The current method involves opening the url in a second window, which then has to be closed once its loaded and ive seen the link works. I was hoping for a more elegent dot.net solution.<BR>Ive had a look through the docs but nothing jumps out as being right for the job.<BR><BR>Any got any ideas?<BR><BR>KristianCheck out the system.net namespace. As long as your server allows you to make an outgoing connection on port 80 you should be fine. Here is an example of how to check a url... I got it from the .net framework sdk. I believe in order to read the data you'll need to use a streamreader class of some kind. I forgot how I did it. This should work to check if a url is valid.. I havent tested this....<BR><BR>Function UrlIsValid(url as String) as Boolean<BR><BR>Try<BR>' Initialize the WebRequest.<BR>Dim myRequest As WebRequest = WebRequest.Create(url)<BR><BR>' Return the response. <BR>Dim myResponse As WebResponse = myRequest.GetResponse()<BR>' Code to use the WebResponse goes here.<BR>' Close the response to free resources.<BR>myResponse.Close()<BR><BR>' Assume url exists because exception wasnt thrown<BR>return true<BR>Catch ex as WebException<BR> ' Server returned error<BR> return false<BR>End try<BR><BR>End Function<BR><BR>Im not sure but if the domain is invalid its possible that that function might cause your aspx page to hang.. In fact even if all your url's were valid it may still take awhile to verify them all. I dont think its a good idea to have it constantly very url's. Maybe you could write a script that you could run once a day to verify the url's... or twice a day.Thanks a lot for that, ill check it out and see how i get on.<BR><BR>Its just for a one time import while i move my links from the existing asp app to the shiny new .net version.<BR><BR>But if it works well theres no reason why i couldnt schedule it as a weekly procedure checking for deadlinks.<BR><BR>Thanks<BR><BR>Kristian