CefSharp load a page with browser login

只愿长相守 提交于 2019-12-01 18:09:33

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.

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;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!