0
votes

Can any one tell me what browser is the client using from the user agent below? If you can, than can you tell me how did you figure it out? I am trying to identify the client browser from .Net and it seems there is no bulletproof way of doing it. I thought the code below should be good enough to get the client browser name but an answer from .Net team states the method is not guarantied.

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240

C#

var req = HttpContext.Current.Request;
var browserName = req.Browser.Browser;

.Net Team answer

Thanks for your feedback. BrowserCap is a legacy feature and we don't keep updating it anymore, unless we find that asp.net feature is broken caused by this. If you really want your app to recognize Edge as Edge(not chrome), then you can add your own browser file to match the UA string of Edge under app_browsers folder. Feedback

Update*: Here are UA strings from three browsers that might suggest that the last piece of information might be the indicator but not for Chrome. As you can see chrome shows Safari/537.36 at the end of the UA so this can't be the indicator. Moreover, there is no safari installed on the system, so why google and Microsoft try to fool us? And I would like to ask them this question; what is the purpose of the User Agent if the information is there to fool us. Lets take it out of the header completely (less bytes to transfer through the internet). If this is the standards than respect them or get rid of them completely. Please correct me if I am making wrong assumptions due to the lack of information.

Edge: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240

Firefox: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0

Chrome: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36

2
3 more user agents (all from OS X): Firefox: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:42.0) Gecko/20100101 Firefox/42.0 Chrome: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2557.0 Safari/537.36 Safari: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/537.86.2davejagoda
Hmm, funny enough but it seems Google and MS have Safari/537.36 In the UA in my and your examples with different OS. This must be the fooling part :-D; It seems so far the most honest browsers are Firefox and Safari. Google is not playing fair and MS tries to copy Google :(Arman
I think Microsoft was the first to copy: quora.com/…davejagoda

2 Answers

1
votes

That is most likely Edge:

Edge/12.10240

http://www.geekwire.com/2015/the-challenge-of-tracking-microsofts-new-edge-browser-in-google-analytics/

Keep in mind, an HTTP client can set its user-agent string, and most of them say they are Mozilla.

Updated in response to question in comments

I think there is no perfect answer to determine what browser the client is using. I know from experience that most browsers claim to be Mozilla and from some experimentation that Chrome and Safari on OS X both mention AppleWebKit. My initial guess was that it was Safari, but after posting an answer to that effect I noticed the browser was claiming to be both Chrome and Safari, and then noticed Edge at the end. According to the Sesame Street school of debugging (one of these things is not like other) I did a search on Edge and found the link above. Another hint: it's the last item in the user-agent string. Suggestion: get a machine and run a bunch of browsers to see what your web logs show.

One other possibly useful detail: (Windows NT 10.0; Win64; x64) narrows the choices slightly - browsers appear to be generally truthful about this data, so that told me it probably wasn't Safari since I don't think Apple offers it on Windows any more.

0
votes

use the request object to retrieve the browser details and more.. Request.Browser.Browser = returns the name of the browser in use Request.Browser.IsMobileDevice = returns true if the request is from a mobile device