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

Using ResourceHandler you can also intercept and handle AJAX requests and determine whether this request should be executed or not. To do this, you need to register your own ResourceHandler implementation. For example:


private class TestResourceHandler : ResourceHandler
    public bool CanLoadResource(ResourceParams parameters)
        if (parameters.ResourceType == ResourceType.XHR)
            Console.WriteLine("Suppress ajax call - " + parameters.URL);
            return false;
        return true;


Private Class TestResourceHandler
    Implements ResourceHandler

    Public Function CanLoadResource(ByVal parameters As ResourceParams) As Boolean _
        Implements ResourceHandler.CanLoadResource
        If parameters.ResourceType = ResourceType.XHR Then
            Console.WriteLine("Suppress ajax call - " & parameters.URL)
            Return False
        End If

        Return True
    End Function
End Class

This resource handler is attached to the network service of the corresponding browser context:


browser.Context.NetworkService.ResourceHandler = new TestResourceHandler();


browser.Context.NetworkService.ResourceHandler = New TestResourceHandler()

Using the parameters variable, you can obtain the request URL and method. If CanLoadResource() returns false, the request will be cancelled.