Note: Advice in this article will only work for DotNetBrowser 1.
See the corresponding article for DotNetBrowser 2 here.

DotNetBrowser provides functionality that allows handling network activity including HTTP requests/responses. You can use the NetworkDelegate to handle all network activity of the Browser instances associated with specified BrowserContext.

With NetworkDelegate you can intercept all HTTP requests/responses headers and obtain information about each request/response stage. Below is the list of all request/response stages:


Fires when a request is about to occur. This event is sent before any TCP connection is made and can be used to redirect requests to another location. It can be used to access and modify POST data of the request when method type is "POST". See example.


Fires when a request is about to occur and the initial headers have been prepared. It allows adding, modifying, and deleting HTTP request headers.


Fires after OnBeforeSendHeaders when a proxy connection is used. Provides information about the proxy connection, and allows adding, modifying, and deleting HTTP request headers.


Fires right before the HTTP headers are sent to the network. This event is informational and it does not allow modifying HTTP headers.


Fires each time that an HTTP(S) response header is received. Due to redirects and authentication requests, this can happen multiple times per request. This event is intended to allow adding, modifying and deleting HTTP response headers, such as incoming Set-Cookie headers.


Fires when a request receives an authentication challenge and is unable to respond using cached credentials. You can use this method to handle "basic" or "digest" authentication.


Fires when a request is about to occur and the initial headers have been prepared. It allows adding, modifying, and deleting HTTP request headers.


Fires when the first byte of the response body is received. For HTTP requests, this means that the status line and response headers are available. This event is informational.


Fires each time when a part of the response body is received. When the whole response body is received, OnCompleted will be fired. This event is informational.


Fires when a request has been processed successfully or failed.


Fires when a request is being destroyed.


Fires when the engine is about to decide whether specified cookies can be set or not.


Fires when the engine is about to decide whether specified cookies can be received and send to a web server.

The following sample demonstrates how to change target URL using OnBeforeURLRequest event and print User-Agent HTTP header value when a user loads


<Window x:Class="WPF.NetworkEvents.MainWindow"
        Title="MainWindow" Height="350" Width="525" >
    <Grid Name="mainLayout">




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

namespace WPF.NetworkEvents
    public partial class MainWindow : Window
        Browser browser;
        WPFBrowserView browserView;

        public MainWindow()
            BrowserContext browserContext = BrowserContext.DefaultContext;
            browserContext.NetworkService.NetworkDelegate = new SampleNetworkDelegate();

            browser = BrowserFactory.Create(browserContext);
            browserView = new WPFBrowserView(browser);

    class SampleNetworkDelegate : DefaultNetworkDelegate {
        public override void OnBeforeURLRequest(BeforeURLRequestParams parameters) {
            // If navigate to, then change URL to
            if (parameters.Url.Equals("")) {

        public override void OnBeforeSendHeaders(BeforeSendHeadersParams parameters) {
            // If navigate to, then print User-Agent header value.
            if (parameters.Url.Equals("")) {
                HttpHeaders headers = parameters.Headers;
                Console.WriteLine("User-Agent: " + headers.GetHeader("User-Agent"));




Imports DotNetBrowser
Imports DotNetBrowser.WPF

Namespace WPF.NetworkEvents
    Class MainWindow
        Dim browser As Browser
        Dim browserView As WPFBrowserView

        Sub New()
            Dim browserContext As BrowserContext = BrowserContext.DefaultContext
            browserContext.NetworkService.NetworkDelegate = New SampleNetworkDelegate()
            browser = BrowserFactory.Create(browserContext)
            browserView = New WPFBrowserView(browser)
        End Sub
    End Class

    Class SampleNetworkDelegate
        Inherits DefaultNetworkDelegate

        Public Overrides Sub OnBeforeURLRequest(parameters As BeforeURLRequestParams)
            If parameters.Url.Equals("") Then
            End If
        End Sub

        Public Overrides Sub OnBeforeSendHeaders(parameters As BeforeSendHeadersParams)
            If parameters.Url.Equals("") Then
                Dim headers As HttpHeaders = parameters.Headers
                Console.WriteLine("User-Agent: " + headers.GetHeader("User-Agent"))
            End If
        End Sub
    End Class
End Namespace