Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used a webbrowser object in my asp.net code to retrieve content from websites. the code runs absolutely fine when execute from visual studio, but after hosting, there is no response. it shows "connecting.... " on the browser tab and loads nothing! I have pasted my code below for your understanding.

===========Webbrowser code=============
VB.NET
Dim url As String = ""
url = "https://google.com/patents/" & ListBox1.SelectedItem.ToString()

Dim thread As New Thread(Sub()
                             Using browser As New WebBrowser()
                                 browser.ScrollBarsEnabled = False
                                 browser.ScriptErrorsSuppressed = True
                                 browser.AllowNavigation = True
                                 browser.Navigate(url)
                                 AddHandler browser.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf DocumentCompleted)
                                 While browser.ReadyState <> WebBrowserReadyState.Complete
                                     System.Windows.Forms.Application.DoEvents()
                                 End While
                             End Using
                         End Sub)
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
=====================================
    Private Sub DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
        Dim browser As WebBrowser = TryCast(sender, WebBrowser)
        Dim webCont As String = browser.Document.Body.InnerHtml
        PlaceHolder2.Controls.Add(New Literal() With {.Text = webCont})
    End Sub


Please help me with a good solution..
Thanks in advance

-SB

What I have tried:

Please see the code given above.
Posted
Updated 13-Sep-16 5:08am

The solution is to re-write your code to not use the browser control. You can access html etc via the WebClient class and others, but it ultimately depends on what it is you want to do.

WebClient Class (System.Net)[^]
 
Share this answer
 
You cannot use the browser control in a web application. The browser control is dependent on a Windows Forms app Form object in order to work properly. Since you can't have a Windows Forms Form object in an ASP.NET app the WebBrowser control won't work.

You have to use some other method, like using the WebClient class, to get your data.
 
Share this answer
 
use Html Agility Pack[^] to retrieve data from a site
note: this is one of the method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900