First of all, I'd like to say thanks for the wealth of information on this site, great job guys!
Anyways, this is my current vex and I'd like any opinions as to whether this will work.
I had medium level exp in VB6 and have jumped in the deep end in .net so be gentleI mostly write PLC code so this is a bit of a sideline for me.
The app I'm writing is designed to monitor information on a predefined website. when it works, it works but I am trying to cover cases where the site can't be reached (either due to network problems or the site being unavailable). I had a case where the site was unavailable and my ISP's decided to open a popup surveyand I'm trying to avoid this happening.
Most of the answers to what I'm trying to do, I got in this thread.
What I'm trying to add to the ping is to verify that the correct site responded and if not then don't send the browser.navigate command.
Here's the code I've come up with -
The Call:
The function:Code:log("scan initiated; URL=" & address & "; ") If My.Computer.Network.IsAvailable Then If SiteIsAvailable(address) Then MyBrowser.Navigate(address) Else log("Error: Could not connect to site: " & address) MsgBox("Error: Could not connect to site: " & address, MsgBoxStyle.Exclamation, AcceptButton) End If Else log("Error: network not connected") MsgBox("Error: network not connected", MsgBoxStyle.Exclamation, AcceptButton) End If
What I'm wondering is if the "If wrespTest.ResponseUri.OriginalString = "http://" & SiteUrl Then" statement would reasonably be expected to identify when a re-direct has occurred to a search page?Code:Private Function SiteIsAvailable(ByVal SiteUrl As String) As Boolean 'SiteUrl should be in the format "www.domain.ext" Dim urlTest As New System.Uri("http://" & SiteUrl) Dim wreqTest As WebRequest SiteIsAvailable = False 'just in case wreqTest = WebRequest.Create(urlTest) Dim wrespTest As System.Net.WebResponse Try wrespTest = wreqTest.GetResponse() wrespTest.Close() wreqTest = Nothing 'Pass If wrespTest.ResponseUri.OriginalString = "http://" & SiteUrl Then SiteIsAvailable = True End If Catch ex As Exception wreqTest = Nothing log(ex.ToString) 'Failed - GTFO, it doesn't exist or it's not the site it's supposed to be End Try End Function
Thanks in advance.


I mostly write PLC code so this is a bit of a sideline for me.
and I'm trying to avoid this happening.
Reply With Quote