Working with Protocol Handlers in DotNetBrowser 1.x

Опубликовано: 01 Февраль 2018
на канале: Embedded Browsers
701
5

In this tutorial we are talking about working with protocol handlers in DotNetBrowser.
Get a free 30-days DotNetBrowser trial licence: https://goo.gl/s1AfUk

About DotNetBrowser:
DotNetBrowser allows embedding a Chromium-based browser to your .NET app to display and process HTML5, CSS3, JavaScript, Flash etc.

For more ideas on using an advanced browser-component in your .NET application, please see examples on DotNetBrowser support site
https://dotnetbrowser.support.teamdev...

Previous tutorials:

How to get DotNetBrowser Evaluation Licence -   • How to get DotNetBrowser Evaluation Licence  

How to Add a Browser Component to WPF Application -    • How to Add a Browser Component to WPF Appl...  

How to Create HTML UI for WPF Application Using DotNetBrowser -   • How to Create HTML UI for WPF Application ...  

How to Add a Browser Component to a Windows Forms Application -    • How to Add a Browser Component to a Window...  

Executing JavaScript from the .NET Side Using DotNetBrowser -    • Executing JavaScript from the .NET Side Us...  

Injecting a .NET Object into JavaScript Using DotNetBrowser -    • Injecting a .NET Object into JavaScript Us...  

Getting or Setting HTML Content in DotNetBrowser -    • Getting or Setting HTML Content in DotNetB...  

Working with Context Menus in DotNetBrowser -    • Working with Context Menus in DotNetBrowse...  

Working with Plugins in DotNetBrowser -    • Working with Plugins in DotNetBrowser 1.x  

Transcript:

00:06 We need to create a WPF solution, reference the DotNetBrowser library using NuGet and add the license file. You can find detailed instructions in our previous tutorials.

00:16 MainWindow markup

00:19 Add the DockPanel and set the LastChildFill property value to ‘true’.

00:23 Add the StackPanel with horizontal orientation into the DockPanel and set its ‘DockPanel.Dock’ property value to ‘Top’.
Inside the StackPanel, create a TextBox named ‘RequestTextBox’ and set its width.

00:54 Next to the TextBox, create a button, set its name and text and create its ‘Click’ event handler.

01:16 Finally, add the WPFBrowserView to the DockPanel, set its name and the initial URL.

01:30 Implementing the MainWindow behaviour. Create the ‘CustomProtocolHandler’ class inherited from the ‘IProtocolHandler’ interface and generate the method stubs.

01:47 Go to the ‘Handle’ method. In this sample we will simply return the URL of the request as the response body. Return the new instance of the ‘UrlResponse’ class. Initialize this instance with the ‘request.Url’ property value transformed to a byte array.
The ‘UrlResponse’ class represents the response data which will be displayed by the Browser. The response data should be provided as a byte array.

02:12 Go to the main window constructor.

02:15 After calling the ‘InitializeComponent’ method, register the new instance of the ‘CustomProtocolHandler’ class as the protocol handler using the ‘Register’ method of the ‘ProtocolService’ class. This method requires the protocol name and the instance of the handler which will be associated with the specified protocol.

02:32 Finally, call the ‘LoadUrl’ method of the browser instance using the text from the ‘RequestTextBox’.

02:42 Now you can build and launch your application. As you can see, the http protocol of the initial URL is handled as usual - the browser instance loads the specified website. But if we specify the registered protocol, the registered handler is called and the browser displays the requested URL.


#DotNetBrowser
#EmbeddedBrowsers
#ProtocolHandlers