Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CefSharp load a page with browser login

I need to ebed a web browser in a Wpf app, I tried with the one from the toolbox but get some issues and went to CefSharp.

public MainWindow()
{
 InitializeComponent();
 BrowserSettings settings = new BrowserSettings();
 Cef.Initialize(new CefSettings());           
CefSharp.Wpf.ChromiumWebBrowser webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
  licence_grid.Children.Add(webBrowser);
  webBrowser.Address = "http://myurlToLoad the page";
}

The problem is when I used a normal url the page load. But when I used the url I intend to use and whith which the user enter his user and password in a browser pop up (I mean not a pop up from the website) . I get an error with this page take yoo much time to load and nothing else. Can someone give me some tracks to follow... Thanks

like image 612
Alain BUFERNE Avatar asked Apr 13 '15 18:04

Alain BUFERNE


2 Answers

It sounds like the popup you are referring to is in fact the site prompting for basic authentication.

In that case you need to provide an IRequestHandler.GetAuthCredentials handler.

like image 142
jornh Avatar answered Oct 19 '22 23:10

jornh


As the question & answer is very old and i would like to give the latest update on this solution, there is slight change as per original solution suggested.

anybody consuming cefsharp need to implement the authentication dialog. and changes in method is

 bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, 
        string host, int port, string realm, string scheme, IAuthCallback callback)
    {
        //NOTE: If you do not wish to implement this method returning false is the default behaviour
        // We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.

        // shyam - original implemenation.
        //callback.Dispose();
        //return false;

        bool handled = false;

        // Instantiate the dialog box
        AuthDialog dlg = new AuthDialog(host); // create new dialog with username and password field.

        // Open the dialog box modally 
        dlg.ShowDialog();

        if (dlg.DialogResult == System.Windows.Forms.DialogResult.OK)
        {
            // The user did not cancel out of the dialog. Retrieve the username and password.
            callback.Continue(dlg.UserName,dlg.Password);
            handled = true;
        }

        return handled;
    }
like image 5
shyam_ Avatar answered Oct 19 '22 21:10

shyam_