I want to open a page that required Basic authentication. I want to pass the Basic authentication header to the browser along with the URL.
How can i do that?
Via a header you can:
string user = "uuuuuuu";
string pass = "ppppppp";
string authHdr = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + pass)) + "\r\n";
webBrowserCtl.Navigate("http://example.com", null, null, authHdr);
given that this needs to be done on a per-request basis, an easier option for basic auth is to just;
webBrowserCtl.Navigate("http://uuuuuuu:[email protected]", null, null, authHdr);
You could try the old "in URL" format which allowed this but it is insecure:
http(s)://username:password@server/resource.ext
This exposes credentials and IE has disabled it, but it may still work in other browsers. When this format is used the credentials are available to the browser and it makes the decision to send the basic authentication header depending on how the web server responds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With