CefSharp使用浏览器登录加载页面

Ala*_*RNE 5 browser wpf load cefsharp

我需要在Wpf应用程序中使用Web浏览器,我尝试使用工具箱中的一个,但是遇到了一些问题并转到了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";
}
Run Code Online (Sandbox Code Playgroud)

问题是当我使用普通网址加载页面时.但是当我使用我想要使用的URL时,用户在浏览器中输入用户和密码(我的意思是不是从网站弹出).我收到这个页面的错误需要花费很多时间来加载,没有别的.有人可以给我一些跟踪的帖子......谢谢

jor*_*rnh 5

听起来你所指的弹出窗口实际上是提示进行basic身份验证的网站.

在这种情况下,您需要提供一个IRequestHandler.GetAuthCredentials处理程序.


shy*_*am_ 5

由于问题和答案非常古老,我想提供此解决方案的最新更新,因此根据原始解决方案的建议略有变化。

任何使用cefsharp的人都需要实现身份验证对话框。方法的变化是

 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;
    }
Run Code Online (Sandbox Code Playgroud)