Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27184

System.Net.WebException was unhandled by user code

$
0
0
I am trying to create a favicon code for a web browser project, and I need to be able to make the code support when the application cannot find the favicon, crashes, and returns this error:


System.Net.WebException was unhandled by user code
Message=The remote server returned an error: (404) Not Found.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Projectname.QtpBrowser.WebBrowser1_LoadingFrameComplete(Object sender, FrameEventArgs e) in C:\Users\enduser\Desktop\Project\Projectname\Projectname\QtpBrowser.vb:line 64
at Awesomium.Windows.Forms.WebControl.ucuPEZy5F0NXHEbe8V(Object , Object , Object )
at Awesomium.Windows.Forms.WebControl.OnLoadingFrameComplete(FrameEventArgs e)
at Awesomium.Windows.Forms.WebControl.Awesomium.Core.IWebViewListener.OnLoadingFrameComplete(FrameEvent Args e)
at Awesomium.Core.WebViewListener.FireEvent(IWebViewListener view, IWebViewEventArgs e)
at Awesomium.Core.WebViewListener.UZ5HRfvyeMyexvRmH9O(Object , Object )
at Awesomium.Core.WebViewListener.nh66wTcj4H(IntPtr , Int64 , Boolean , Uri )
at Awesomium.Core.NativeMethods.WebCore_Update(HandleRef jarg1)
at Awesomium.Core.WebCore.BhfWowI6aE()
InnerException:



This is the full code I have for retrieving the favicon, and displaying it in a picturebox:
Code:

Dim url As Uri = New Uri(MainBrowser.BrowserAddressBar.Text)


        If url.HostNameType = UriHostNameType.Dns Then

            ' Get the URL of the favicon


            Dim iconURL = "http://" & url.Host & "/favicon.ico"


            ' Download the favicon

            Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(iconURL)

            Dim response As System.Net.HttpWebResponse = CType(request.GetResponse(), Net.HttpWebResponse)

            Dim stream As System.IO.Stream = response.GetResponseStream()

            Dim favicon = Image.FromStream(stream)


            ' Display the favicon on PictureBox1

            MainBrowser.WebpageFavicon.Image = favicon

            If Not stream Is Nothing Then
               
                MainBrowser.WebpageFavicon.Image = favicon
            End If


        End If


The bolded out part of the code is the part I attempted to use which obviously didn't work. As you can see, it isn't complete. Any help would be appreciated guys. Thanks.

Viewing all articles
Browse latest Browse all 27184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>