Note: Advice in this article will only work for DotNetBrowser 1.
See the corresponding article for DotNetBrowser 2 here.
In DotNetBrowser 1.7 the Certificate Validation API has been introduced. Using this API you can get information about each SSL certificate used for displaying HTTPS web pages and decide whether it should be accepted or rejected. By default, Chromium engine decides whether certificate should be accepted/rejected. You can register your own CertificateVerifier
implementation to modify default behavior. For example:
C#
using DotNetBrowser; using DotNetBrowser.WPF; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; namespace CertificateVerifierSample { /// <summary> /// The sample demonstrates how to accept/reject SSL certificates using /// custom SSL certificate verifier. /// </summary> public class WindowMain : Window { private WPFBrowserView browserView; class TestCertificateVerifier : CertificateVerifier { public CertificateVerifyResult Verify(CertificateVerifyParams parameters) { // Reject SSL certificate for all "google.com" hosts. if (parameters.HostName.Contains("google.com")) { return CertificateVerifyResult.INVALID; } return CertificateVerifyResult.OK; } } public WindowMain() { BrowserContext browserContext = BrowserContext.DefaultContext; Browser browser = BrowserFactory.Create(browserContext); //add custom request handler browser.Context.NetworkService.CertificateVerifier = new TestCertificateVerifier(); browserView = new WPFBrowserView(browser); Content = browserView; Width = 1024; Height = 768; this.Loaded += WindowMain_Loaded; } void WindowMain_Loaded(object sender, RoutedEventArgs e) { browserView.Browser.LoadURL("http://google.com"); } [STAThread] public static void Main() { Application app = new Application(); WindowMain wnd = new WindowMain(); app.Run(wnd); var browser = wnd.browserView.Browser; wnd.browserView.Dispose(); browser.Dispose(); } } }
VB.NET
Imports DotNetBrowser Imports DotNetBrowser.WPF Imports System.Windows Module CertificateVerifierSample ''' <summary> ''' The sample demonstrates how to accept/reject SSL certificates using ''' custom SSL certificate verifier. ''' </summary> Public Class WindowMain Inherits Window Private browserView As WPFBrowserView Class TestCertificateVerifier Implements CertificateVerifier Public Function Verify(ByVal parameters As CertificateVerifyParams) As CertificateVerifyResult _ Implements CertificateVerifier.Verify 'Reject SSL certificate for all "google.com" hosts. If parameters.HostName.Contains("google.com") Then Return CertificateVerifyResult.INVALID End If Return CertificateVerifyResult.OK End Function End Class Public Sub New() Dim browserContext As BrowserContext = BrowserContext.DefaultContext Dim browser As Browser = BrowserFactory.Create(browserContext) 'add custom request handler browser.Context.NetworkService.CertificateVerifier = New TestCertificateVerifier() browserView = New WPFBrowserView(browser) Content = browserView Width = 1024 Height = 768 AddHandler Me.Loaded, AddressOf WindowMain_Loaded End Sub Private Sub WindowMain_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) browserView.Browser.LoadURL("http://google.com") End Sub <STAThread> Public Shared Sub Main() Dim app As Application = New Application() Dim wnd As WindowMain = New WindowMain() app.Run(wnd) Dim browser = wnd.browserView.Browser wnd.browserView.Dispose() browser.Dispose() End Sub End Class End Module