0
votes

I am trying to use the follwing code to force user agent for the webbrowser in my app.

webBrowser.Navigate("http://localhost/run.php", null, null, "User-Agent: Here Put The User Agent");

However VS wont accept this code, giving me error.

No overload for method 'Navigate' takes 4 arguments

What am I missing?

2

2 Answers

3
votes

According to this and this there is no Navigate with more than one parameter available in Silverlight - so VS is right... the code you show would work with .NET 4 but not with Silverlight.

I don't see an option to set any header in the Silverlight WebBrowser control so I would suspect that what you want to is not possible with Silverlight... depending on your usecase it might be possible to use WebClient and/or HttpWebRequest to achieve what you want (BEWARE these don't render!).

0
votes

You might want to try this approach: download the HTML content manually using WebClient and setting the UserAgent header (webClient.Headers[ HttpRequestHeader.UserAgent ] = "my custom user agent string"), then set the content into the WebBrowser control using the NavigateToString method.

Some headers have restricted use in Silverlight, and different restrictions in Silverlight for Windows Phone, and I've been misled at least once on this score, so I don't know without trying and running it if you have write access to UserAgent on the platform.

You might also need set the Accept header to a value like "application/xhtml+xml, text/html, /" which is what IE9 uses for the Accept header; "text/html" would probably do just fine; not setting an Accepts header might work, too.