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

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...