CefSharp load a page with browser login

前端 未结 2 2202
天命终不由人
天命终不由人 2021-01-19 03:16

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()
{
 Initialize         


        
相关标签:
2条回答
  • 2021-01-19 03:30

    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;
        }
    
    0 讨论(0)
  • 2021-01-19 03:39

    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.

    0 讨论(0)
提交回复
热议问题