Note: this article contains a sample created for DotNetBrowser versions prior to 1.13. If you are using DotNetBrowser 1.13 or a more recent version, you should consider using the Custom Protocol Handler instead.

C#

using DotNetBrowser;
using DotNetBrowser.WPF;
using System;
using System.Windows;

namespace CustomRequestHandlingSample
{
    class Program
    {
        public class WindowMain : Window
        {
            private WPFBrowserView browserView;

            private class CustomResponseEventArgs : EventArgs
            {
                public string Url { get; private set; }

                public CustomResponseEventArgs(string url)
                {
                    Url = url;
                }
            }
            private delegate void CustomResponseHandler(object sender, CustomResponseEventArgs e);

            private class CustomLoadHandler : DefaultLoadHandler
            {
                public event CustomResponseHandler CustomResponseEvent;

                public override bool OnLoad(LoadParams loadParams)
                {
                    if (loadParams.Url.StartsWith(@"myscheme://"))
                    {
                        var customResponseEvent = CustomResponseEvent;
                        if (customResponseEvent != null)
                        {
                            customResponseEvent.Invoke(this, new CustomResponseEventArgs(loadParams.Url));
                        }
                    }

                    return false;
                }
            }

            public WindowMain()
            {
                Browser browser = BrowserFactory.Create();

                //add custom request handler
                var customLoadHandler = new CustomLoadHandler();

                customLoadHandler.CustomResponseEvent += delegate (object sender, CustomResponseEventArgs e)
                {
                    if (e.Url.Contains(@"myscheme://test1"))
                    {
                        browser.Stop();
                        browser.LoadURL(@"http://google.com");
                    }
                };

                browser.LoadHandler = customLoadHandler;

                browserView = new WPFBrowserView(browser);
                Content = browserView;

                Width = 1024;
                Height = 768;
                this.Loaded += WindowMain_Loaded;
            }

            void WindowMain_Loaded(object sender, RoutedEventArgs e)
            {
                browserView.Browser.LoadURL("myscheme://test1");
            }

            [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 CustomRequestHandlingSample
    Public Class WindowMain
        Inherits Window

        Private browserView As WPFBrowserView

        Private Class CustomResponseEventArgs
            Inherits EventArgs

            Public Property Url As String

            Public Sub New(ByVal url As String)
                Me.Url = url
            End Sub
        End Class

        Private Delegate Sub CustomResponseHandler(ByVal sender As Object, ByVal e As CustomResponseEventArgs)

        Private Class CustomLoadHandler
            Inherits DefaultLoadHandler

            Public Event CustomResponseEvent As CustomResponseHandler

            Public Overrides Function OnLoad(ByVal loadParams As LoadParams) As Boolean
                If loadParams.Url.StartsWith("myscheme://") Then
                    Dim customResponseEvent As CustomResponseHandler  = CustomResponseEventEvent

                    If customResponseEvent IsNot Nothing Then
                        customResponseEvent.Invoke(Me, New CustomResponseEventArgs(loadParams.Url))
                    End If
                End If

                Return False
            End Function
        End Class

        Public Sub New()
            Dim browser As Browser = BrowserFactory.Create()
            ' add custom request handler
            Dim customLoadHandler = New CustomLoadHandler()

            AddHandler customLoadHandler.CustomResponseEvent,
                Sub(ByVal sender As Object, ByVal e As CustomResponseEventArgs)

                    If e.Url IsNot Nothing AndAlso e.Url.Contains("myscheme://test1") Then
                        browser.Stop()
                        browser.LoadURL("http://google.com")
                    End If
                End Sub

            browser.LoadHandler = customLoadHandler

            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("myscheme://test1")
        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