Here is my code:
Dim TestHeader As String = "Referer: http://www.testrefferer.com"
If chkRefferer.Checked = True Then
WebBrowser1.Navigate(cmbUrl.Text, False, Nothing, TestHeader)
Else
WebBrowser1.Navigate(cmbUrl.Text)
End If
Whenever I try and browse to a page with the 'TestHeader', IE opens up and goes to the page.... However, if I navigate to the same page without the additional header, it loads up fine in my webbrowser control.
Why would this be?
I have changed the 'False' to "_self" and it now works.
Related
I am using in a WinForm an object of type:
CefSharp.WinForms.ChromiumWebBrowser
Everything is working fine but I am having an issue when I try to change the ZoomLevel with SetZoomLevel method:
If oBrowser.IsBrowserInitialized Then
oBrowser.SetZoomLevel(-2.0)
Dim frame As CefSharp.IFrame = oBrowser.GetMainFrame
Dim request As CefSharp.IRequest = frame.CreateRequest()
request.Url = url
request.Method = "POST"
request.InitializePostData()
Dim element = request.PostData.CreatePostDataElement()
element.Bytes = postDataBytes
request.PostData.AddElement(element)
request.Headers = headers
frame.LoadRequest(request)
End If
The first time I open the WinForm the Zoom level doesn't change, while it works correctly from the 2nd refresh.
Am I missing some initialization and/or method call... Or do I have to call this method in another position?
Note: the CEFSharp DLL version is 63.0.3.0.
The .NET Framework is 4.5.2
EDITED 01.06.2018: I've found a solution (see below) but now there's another problem: the zoom change is made when the browser is already visible, so it's not nice for the final user to see the page size changing during the form load.
Has anyone a suggestion to freeze the layout during zoom change? Please note that .SuspendLayout() and .ResumeLayout() are not working.
I've found a way to answer my own question. I post it here as it could be useful to other users.
You must add a LoadingStateChanged handler to the ChromiumWebBrowser object:
AddHandler oBrowser.LoadingStateChanged, AddressOf WebBrowserOnLoadingStateChanged
The method would be then something like:
Private Sub WebBrowserOnLoadingStateChanged(ByVal sender As Object, ByVal loadingStateChangedEventArgs As LoadingStateChangedEventArgs)
Dim oBrowser As WinForms.ChromiumWebBrowser = CType(sender, WinForms.ChromiumWebBrowser)
If Not oBrowser.IsLoading Then
oBrowser.SetZoomLevel(-2.0)
End If
End Sub
This solution works good in my environment but now there's another problem: the zoom change is made when the browser is already visible, so it's not nice for the final user to see the Zoom Level changing during the form load.
I have a situation in which I have a aspx page ,that hit on schedule ,all my logic is written in this page.I want that while this page is hit on schedule time,no console window or page that was hit,will not show up.what I have done to hide console window ,
1.just change it to window application output in application setting.
2.and to start aspx page
Dim url As String = ""
url = ConfigurationManager.AppSettings("www.youtube.com")
Process.Start(url)
But Problem is when that page is hit using this code ,that page open up in browser?
if you any logic written in web page code behind that you need to execute from many places, ideally you should move that to a common library project accessible to all other projects.
I am not much clear why we need to execute a web page from console, still you can use WebRequest and WebResponse classes to get the output of the web page without opening in browser.
Dim _request As WebRequest = WebRequest.Create("www.youtube.com")
_request.GetResponse()
Old Answer
using _response As WebResponse = _request.GetResponse()
Using _reader As New StreamReader(_response.GetResponseStream())
Dim _html As String = _reader.ReadToEnd()
End Using
End Using
here is a simple code to run a page without open it in browser.
Dim url As String = ""
url = ConfigurationManager.AppSettings("url")
Dim client As New WebClient
client.DownloadString(url)
client.Dispose()
I have a WebBrowser in my VB.net form. I want to disable from users clicking links in the Webbrowser, but still able to scroll the Webbrowser.
I found this code but it locks up the whole WebBroswers so I can't click links or scroll, but I need to be able to scroll.
DirectCast(WebBrowser1, Control).Enabled = False
Just set the following property:
WebBrowser1.AllowNavigation = False
A hacky work-around to change the address from code would be to turn AllowNavigation on again, but it requires a BeginInvoke to allow the navigation to take place before turning it off again:
WebBrowser1.AllowNavigation = True
WebBrowser1.Navigate("new web address...")
Me.BeginInvoke(New Action(Sub() WebBrowser1.AllowNavigation = False))
I'm sure I'm doing my login process for my app in a not so perfect way, but as with lots of things, it works. The issue is to make it work I have to use the very unpopular DoEvents thing.
I would like my application to show a login screen before loading my main form. Currently I have a login dialog box with a FormOpen boolean property and an authenticated boolean property. If a user logs in successfully, I hide the login form, set formopen to false, and authenticated to true. If they cancel out, then I do the same and just set the authenticated property to false. If authenticated=false then I end the app, else I show the main form via application.run(MainForm)
Shared Sub Main()
Using frmLogin1 As New LoginForm
frmLogin1.Show()
Do While frmLogin1.FormOpen = True
Application.DoEvents()
Loop
If frmLogin1.Authenticated = False Then End
End Using
ModuleRegistration.Register()
Application.Run(MainForm)
End Sub
Is there a more preferred way of doing this?
You could just set the startup form to the login form. Then when the user hits "OK" and is verified, you just load the main form and close the login form.
Alternatively you can use the "ShowDialog" method to show the form modally. In your login form code, you can set DialogResult when closing the form, which becomes the return value from the ShowDialog method. That way you can detect that, say, "Cancel" was pressed and quit.
UPDATE: Perhaps if you change your Sub Main to just:
Application.Run(YourLoginForm)
Along with whatever other startup code your require. Then handle showing the main form in your login form (if I remember correctly, your application will not exit until the last form closes... You can use that to your advantage).
I think your approach is fine, except for one thing: the loop. Instead, display the login form using ShowDialog.
Shared Sub Main()
Dim authenticated As Boolean
Using frmLogin1 As New LoginForm
frmLogin1.ShowDialog()
authenticated = frmLogin1.Authenticated
End Using
If authenticated Then
ModuleRegistration.Register()
Application.Run(MainForm)
End If
End Sub
Or instead of waiting for your login form to close, raise an event in the login form.
You'll need to declare your login form withevents.
Then when the login form's new event fires, check the value of the authenticated property.
I've got a VB.NET class that is invoked with a context menu extension in Internet Explorer.
The code has access to the object model of the page, and reading data is not a problem. This is the code of a test function...it changes the status bar text (OK), prints the page HTML (OK), changes the HTML by adding a text and prints again the page HTML (OK, in the second pop-up my added text is in the HTML)
But the Internet Explorer window doesn't show it. Where am I doing wrong?
Public Sub CallingTest(ByRef Source As Object)
Dim D As mshtml.HTMLDocument = Source.document
Source.status = "Working..."
Dim H As String = D.documentElement.innerHTML()
MsgBox(H)
D.documentElement.insertAdjacentText("beforeEnd", "ThisIsATest")
H = D.documentElement.outerHTML()
MsgBox(H)
Source.status = ""
End Sub
The function is called like this from JavaScript:
<script>
var EB = new ActiveXObject("MyObject.MyClass");
EB.CallingTest(external.menuArguments);
</script>
To the best of my understanding, in order to use insertAdjacentText or any of the other editing methods, the document object should be in the design mode.
In design mode you can edit the document freely, and so can the user.
Check this site for more details
I do not think that Alex is right, something else is the matter.
When I tried to do something like that, insertBefore would not work for me, but appendChild worked just fine, so adding an element is possible.
I worked in Javascript, but I don't expect that makes a difference.