1

Hopefully this won't be too painful...

I am trying to access a website from a webbrowser control, I have tried two methods (well actually, lots more from googling with mixed results) that have the following problems:

 URL = "http://username:password@thewebsite.com"
 WebBrowser1.Navigate(URL)

1: This method results in a window security pop up, asking me to log in to the company proxy. I guess this is because I am using the username/password for the website and the URL navigation is attempting to input it to the proxy?

If I attempt to automate/avoid the proxy bit by doing this:

Dim Headers As String = "Proxy-Authorization: Basic " & Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("USERNAME:PASSWORD"))
WebBrowser1.Navigate(URL, "", Encoding.Unicode.GetBytes(String.Empty), Headers)

I still meet with failure as the proxy log in box pops up regardless.

2: If I go straight to the website without editing the URL:

 URL = "http://thewebsite.com"
 WebBrowser1.Navigate(URL)

Then it takes me to teh website without any proxy messages at all (great!) but the website then pops up a log in box that I need to populate. Sadly I cannot get hold of any elementids for this (to automate) as it is a windows form pop up outside of the webbrowser control, and I cannot seem to interrogate it or figure out how to input into it.

Does anyone have any ideas for what I should try next? Is there some way to get the login form from method 2 to either populate itself or at least let me view the source of that page? I cannot click away from it until it is populated correctly.

I just cannot seem to get anything to work that will deal with both log in forms for me, it is either one or the other. (both forms look like windows standard log in prompts, they are not built into the webpage). Thanks

Yonabart
  • 68
  • 1
  • 11
  • Suppressing Hosted WebBrowser Control Dialogs http://www.codeproject.com/Articles/31163/Suppressing-Hosted-WebBrowser-Control-Dialogs – volody Sep 05 '13 at 13:49

1 Answers1

1

You'd need to implement a custom browser control site supporting IServiceProvider and provide IAuthenticate as service. The browser control will call back your IAuthenticate implementation whenever it needs login credentials.

The following q/a might help you to get started, although the code is in C#:

WEbbrowser control autheticate not working when access file folder [original spelling preserved].

Implement IDispatch::Invoke to be called by a WebBrowser control.

[EDITED] More specifically, you'd need to implement IAuthenticateEx, which would allow you to differentiate between proxy and website authentication via AUTHENTICATEINFO.dwFlags.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486
  • 1
    Noseration to the rescue again! Thanks for this, I have been pulled onto a different project for the remainder of this week, but will give feedback on this answer when I return to this work next week. – Yonabart Sep 05 '13 at 07:19
  • No problem :] I really don't know how feasible it'd be with VB.NET, but if you have a choice, you may want to create a separate assembly in C# for a custom `WebBrowser` wrapper class like [this](http://stackoverflow.com/questions/7608550/implement-idispatchinvoke-to-be-called-by-a-webbrowser-control). – noseratio Sep 05 '13 at 14:22
  • 1
    I've managed to get the above working (mostly) in VB. However, I am still failing to catch both authentication requests and automate them at the same time. I did however, modify the above to get to a point where the website login form pops up and is auto-filled (proxy form never presents). it just requires a user to select enter. This is good enough compromise for us at the moment (sadly work are pressuring me to move on to something else). Therefore I will leave this for now. I am leaving this question open, in case someone else comes up with another idea for the future. Thanks again. – Yonabart Sep 18 '13 at 10:12
  • 1
    Well done! I wonder if you tried [Silent](http://msdn.microsoft.com/en-us/library/aa768269(v=vs.85).aspx) property in hope to avoid requiring a user to hit enter. – noseratio Sep 18 '13 at 10:22
  • I'm want to do the same in VB.NET but when I translate the code using http://www.developerfusion.com/tools/convert/csharp-to-vb/ the code that comes out is not usable in VB.net. Poggy would you be willing to share your code?, thnx! @Poggy – Dennis May 12 '14 at 12:02
  • @Lectere, if you want to be heard by another person in the comment (apart from the OP), you should add `@` to the username. – noseratio May 12 '14 at 12:05
  • Damn, ur quick!, I've added the @ for @Poggy – Dennis May 12 '14 at 12:07
  • @Lectere, that's SO Android app notifying me :) – noseratio May 12 '14 at 12:30
  • @Lectere, I've only just spotted this now. Do you still need some help on this? I've had a look at my old code, and its fairly basic to be honest. We did faff with this for a bit, but in the end we put something into the company firewall and user's registry settings to do the hard work for us. – Yonabart Jun 03 '14 at 12:09