Using DotNetBrowser DialogHandler API you can handle the situation when Select SSL Certificate dialog should be displayed. By default, DotNetBrowser displays its own implementation of the dialog where the user can select required certificate in the list of available certificates. In order to override the default behavior, you must register your own implementation of the DialogHandlerinterface with overridden DialogHandler.OnSelectCertificate(CertificatesDialogParams parameters)method. In your implementation, you can display your own dialog or suppress the dialog and select required certificate programmatically.


The following sample demonstrates how to override default implementation with custom Select SSL Certificate dialog:

C#

using System;
using System.Collections.Generic;
using DotNetBrowser;

namespace CertificateSelectSample
{
    /// <summary>
    /// Demonstrates how to handle SSL certificate selection.
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            Browser browser = BrowserFactory.Create();
            browser.DialogHandler = new SampleDialogHandler((selectCertificateParameters) =>
            {
                String message = "Select a certificate to authenticate yourself to " +
                                 selectCertificateParameters.HostPortPair.HostPort;
                Console.WriteLine(message);

                List<Certificate> certificates = selectCertificateParameters.Certificates;
                if (!(certificates.Count == 0))
                {
                    Object selectedValue = certificates[0];
                    if (selectedValue != null)
                    {
                        selectCertificateParameters.SelectedCertificate = ((Certificate) selectedValue);
                        return CloseStatus.OK;
                    }
                }

                return CloseStatus.CANCEL;
            });
            browser.LoadURL("<URL that causes Select SSL Certificate dialog>");
        }

        private class SampleDialogHandler : DialogHandler
        {
            private Func<CertificatesDialogParams, CloseStatus> certificateAction;

            public SampleDialogHandler(Func<CertificatesDialogParams, CloseStatus> certificateAction)
            {
                this.certificateAction = certificateAction;
            }

            public void OnAlert(DialogParams parameters)
            {
            }

            public CloseStatus OnConfirmation(DialogParams parameters)
            {
                return CloseStatus.CANCEL;
            }

            public CloseStatus OnPrompt(PromptDialogParams parameters)
            {
                return CloseStatus.CANCEL;
            }

            public CloseStatus OnFileChooser(FileChooserParams parameters)
            {
                return CloseStatus.CANCEL;
            }

            public CloseStatus OnBeforeUnload(UnloadDialogParams parameters)
            {
                return CloseStatus.CANCEL;
            }

            public CloseStatus OnSelectCertificate(CertificatesDialogParams parameters)
            {
                return certificateAction(parameters);
            }

            public CloseStatus OnReloadPostData(ReloadPostDataParams parameters)
            {
                return CloseStatus.CANCEL;
            }

            public CloseStatus OnColorChooser(ColorChooserParams parameters)
            {
                return CloseStatus.CANCEL;
            }
        }
    }
}

VB.NET

Imports DotNetBrowser

''' <summary>
'''Demonstrates how to handle SSL certificate selection.
''' </summary>
Module CertificateSelectSample
    Sub Main()
        Dim browser As Browser = BrowserFactory.Create()
        browser.DialogHandler = new SampleDialogHandler()
        browser.LoadURL("<URL that causes Select SSL Certificate dialog>")
    End Sub

    Friend Class SampleDialogHandler
        Implements DialogHandler

        Public Sub OnAlert(parameters As DialogParams) Implements DialogHandler.OnAlert
        End Sub

        Public Function OnConfirmation(parameters As DialogParams) As CloseStatus _
            Implements DialogHandler.OnConfirmation
            Return CloseStatus.CANCEL
        End Function

        Public Function OnPrompt(parameters As PromptDialogParams) As CloseStatus Implements DialogHandler.OnPrompt
            Return CloseStatus.CANCEL
        End Function

        Public Function OnFileChooser(parameters As FileChooserParams) As CloseStatus _
            Implements DialogHandler.OnFileChooser
            Return CloseStatus.CANCEL
        End Function

        Public Function OnBeforeUnload(parameters As UnloadDialogParams) As CloseStatus _
            Implements DialogHandler.OnBeforeUnload
            Return CloseStatus.CANCEL
        End Function

        Public Function OnSelectCertificate(parameters As CertificatesDialogParams) As CloseStatus _
            Implements DialogHandler.OnSelectCertificate
            Dim message As String = "Select a certificate to authenticate yourself to " +
                                    parameters.HostPortPair.HostPort
            Console.WriteLine(message)
            Dim certificates As List(Of Certificate) = parameters.Certificates
            If Not (certificates.Count = 0) Then
                Dim selectedValue As Object = certificates.Item(0)
                If selectedValue IsNot Nothing Then
                    parameters.SelectedCertificate = CType(selectedValue, Certificate)
                    Return CloseStatus.OK
                End If
            End If
            Return CloseStatus.CANCEL
        End Function

        Public Function OnReloadPostData(parameters As ReloadPostDataParams) As CloseStatus _
            Implements DialogHandler.OnReloadPostData
            Return CloseStatus.CANCEL
        End Function

        Public Function OnColorChooser(parameters As ColorChooserParams) As CloseStatus _
            Implements DialogHandler.OnColorChooser
            Return CloseStatus.CANCEL
        End Function
    End Class
End Module