How to disable “Security Alert” window in Webbrowser control

前端 未结 5 1370
北海茫月
北海茫月 2020-12-01 15:02

I\'m using Webbrowser control to login to HTTPS site with \"untrusted certificate\". but I get popup such standart window \"Security Alert\" about untrusted certificate:

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 15:46

    Here,we go with the solution: I run it on the Browser_Navigated event as the underlying activeX component is null until then.

    Ref:https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f686de1-8884-4a8d-8ec5-ae4eff8ce6db/new-wpf-webbrowser-how-do-i-suppress-script-errors?forum=wpf

             private void Browser_Navigating_1(object sender, NavigatingCancelEventArgs e)
            {
            HideScriptErrors(Browser,true);
    
            }
    
        public void HideScriptErrors(WebBrowser wb, bool Hide)
        {
    
            FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fiComWebBrowser == null) return;
            object objComWebBrowser = fiComWebBrowser.GetValue(wb);
    
            if (objComWebBrowser == null) return;
    
            objComWebBrowser.GetType().InvokeMember(
            "Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { Hide });
    
        }
    

提交回复
热议问题