How to Set Custom User Agent for a WebView in Windows 10 ?

When working with the WebView in Universal Windows Platform app , there are times when you want to pass a custom user agent along with the request.

The WebView in Windows 10 includes a method called NavigateWithHttpRequestMessage which lets you pass the object of type HttpRequestMessage. We could use the Header property of the HttpRequestMessage and set the user agent of the request as shown below.

How to Set Custom User Agent for a WebView in Windows 10 ?

var httpRequestMessage = new Windows.Web.Http.HttpRequestMessage(Windows.Web.Http.HttpMethod.Get, new Uri("http://DeveloperPublish.com"));
httpRequestMessage.Headers.Add("User-Agent", "DeveloperPublishUserAgent");
webView1.NavigateWithHttpRequestMessage(httpRequestMessage);

    1 Comment

  1. Filipe
    August 13, 2016
    Reply

    Hello! Where cam I put this on my code?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...