Reputation: 2548
So in my code I have:
return Request.Browser.Browser + " " + Request.Browser.MajorVersion
When I user Opera, I've had version 21 and now the latest version 33, but my code always returns Chrome. It returned "Chrome 34" for Opera 21, and "Chrome 46" for Opera 33.
Why is this happening and how do I fix it?
Upvotes: 3
Views: 844
Reputation: 413
The user agent strings for Chrome and Opera are nearly the exact same. Only the end differs.
I'm using Opera version 33.0.1990.58 and Chrome version is 46.0.2490.86.
Here'r the user agents I get from each:
Chrome 46 = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
Opera 33 = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36 OPR/33.0.1990.58
In Microsoft.NET/Framework/YOURVERSION/Config/Browsers you can see the XML that shows .NET how to parse agent strings. The chrome.browser identification is: in .NET 4.0.
In that same directory, the Opera.browser identification looks like: /" />.
So Opera shows itself as Chrome because .NET doesn't know any better sine the Opera user agent doesn't fit the regex that .NET is looking for.
Upvotes: 1