Get UserAgent for user's default browser

I am creating an application containing a WebBrowser element, and I would like the application to show useragent for this default user browser.

I know how to get both the default browser through the registry keys and how to get the user agent for the browser, but I can’t understand how to combine these two. Is it possible?

+4
source share
2 answers

What I would do (of course, this is a bit overkill) is to turn on the web server and request the URL from this web server, thus obtaining a user agent.

those. roughly this will include:

  • Embedding a web server inside an application, for example. this
  • Let the WebBrowser call the local URL of the web server (for example, http://127.0.0.1:48384/test )
  • In the web server request handler, store the user agent in a variable
  • Show this variable to end users (for example, in a Label control in a WinForm application or simply by sending a response from a web server.

I have successfully used the web server inside my applications several times. An example is my HTML control in a Code project.

+1
source

Try it (this is a simple function to check if the browser has a handheld device)

 string strUserAgent = Request.UserAgent.ToString().ToLower(); bool status = false; if (strUserAgent != null) { if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") || strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") || strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") || strUserAgent.Contains("palm")) { status = true; } } 
0
source

Source: https://habr.com/ru/post/1411103/


All Articles