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

时间:2015-04-13 18:52:12

标签: wpf browser 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";
}

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

2 个答案:

答案 0 :(得分:5)

听起来您所指的弹出窗口实际上是提示basic身份验证的网站。

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

答案 1 :(得分: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;
    }