2

I am writing a C# application in which I need to retrieve the users browser type.

I get the above from the Request object, specifically from: Request.Browser.Type which a member of System.Web.HttpBrowserCapabilitiesBase.

The result I get from this is not consistent. Most of the time it is correct returning the users browser, eg IE7 etc but the odd time it returns the value "Desktop". I don't understand why this is being returned as obviously it is not correct as the user is visiting the web site via a web browser.

Anyone know why this is being returned and how I might "fix" it or use another way of consistently getting the users browser type?

amateur
  • 43,371
  • 65
  • 192
  • 320
  • 1
    Under what circumstances does it return "Desktop" – Ben Robinson Sep 06 '11 at 16:32
  • It is inconsistent. There is no particular circumstance in which this is returned as oppose to the correct browser being returned. – amateur Sep 06 '11 at 16:41
  • When you say it is inconsistent do you mean that you have tested and the same browser on the same machine will sometimes return "desktop" and sometimes not or do you mean that you have been unable to spot the pattern – Ben Robinson Sep 06 '11 at 16:49
  • I have been unable to spot the pattern. I am logging the information to a text file for users who visit the site and there are several entries in this log where the browser on one occasion is IE7 and a second later its Desktop. So that's confusing me! – amateur Sep 06 '11 at 16:59
  • It probably means that asp.net cannot determine the browser from the useragaent string or no useragent is being sent or something similar. It could be caused by almost anything from some malware on the user's PC, to anti virus web site scanner, to grease monkey scripts and on and on. – Ben Robinson Sep 06 '11 at 17:04
  • What is the actual user agent string for that value? – Tejs Sep 06 '11 at 17:15

1 Answers1

1

ASP.Net does not have Chrome info in its database so therefore it cannot detect it automatically except saying Desktop ... which really indicate it is desktop computer browser not a mobile browser. You can mess around with Request.browser.browsers and so on and the best you will get is AppleSafari

However there are alternatives that exist since long and works for many.

Here is the link for alternative which should give you capability to detect chrome.

http://weblogs.asp.net/ricardoperes/archive/2009/09/22/detecting-chrome-browser-in-asp-net.aspx

Adnan Bhatti
  • 3,410
  • 4
  • 25
  • 38