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);
Pin It

One thought on “How to Set Custom User Agent for a WebView in Windows 10 ?

Leave a Reply

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