How to specify referrer URI when navigating to a page in UWP WebView in C# and VB

When navigating a UWP WebView to a new URI, you may want to specify a referrer URI. When using the UWP WebView, we can do this using the NavigateWithHttpRequestMessage function. To use this function, we need to create a HttpRequestMessage. From an HttpRequestMessage, we can specify a URI to navigate to and referrer URI, amongst many things.

C#:

Windows.Web.Http.HttpRequestMessage Request = new Windows.Web.Http.HttpRequestMessage();

Request.Headers.Referer = new Uri("https://www.quinnscomputing.com");

Request.RequestUri = new Uri("https://codingguides.quinnscomputing.com");

webViewMain.NavigateWithHttpRequestMessage(Request);

VB:

Dim Request = New Windows.Web.Http.HttpRequestMessage()

Request.Headers.Referer = New Uri("https://www.quinnscomputing.com")

Request.RequestUri = New Uri("https://codingguides.quinnscomputing.com")

webViewMain.NavigateWithHttpRequestMessage(Request)

This will navigate the WebView to the specified URI with the specified referrer URI.


This snippet is available in Codly. Click the appropriate link below to download the snippet. If you don't have Codly, it is available here in the Microsoft Store.

Comments

Popular posts from this blog

How to enable dark title bar in Windows Forms and WPF (Windows Presentation Foundation) apps

How to show placeholder text in a WPF textbox

How to enable precision scrolling in a WPF app on Windows