Invalid server side browser detection

I have an ASP.NET MVC 4 application and I am having server side browser detection issues. Client with Opera userAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36 OPR/25.0.1614.63"

send a request, but for the browser name identified as "Chrome" and this is wrong.

var browserName = Request.Browser.Browser;

      

I want to browserName

be defined as "Opera". I tried to override object creation Request.Browser

.


Solution 1:

I created a file "browserCaps.config" and added an xml element for Opera to this file.

<browserCaps>
  <use var="HTTP_USER_AGENT" />
      ...
      <case match="Chrome/\d+\.\d+\.\d+.\d+\sSafari/\d+\.\d+\sOPR/(?'version'(?'major'\d+)(?'minor'\.\d+)\.\d+.\d+)">
        browser=Opera
        version=${version}
        majorversion=${major}
        minorversion=${minor}
      </case>
      ...
</browserCaps>

      

It works great, but I don't like this solution because it overrides all browsers and I need to update it manually.


Solution 2:

I added the file "opera.browser" to the "App_Browsers" folder:

<browsers>
   <browser id="Opera" parentID="Chrome">
      <identification>
         <userAgent match="OPR/(?'version'(?'major'\d+)(\.(?'minor'\d+)?)\w*)" />
      </identification>

      <capabilities>
         <capability name="browser" value="Opera" />
         <capability name="majorversion" value="${major}" />
         <capability name="minorversion" value="${minor}" />
         <capability name="type" value="Opera${major}" />
         <capability name="version" value="${version}" />
      </capabilities>
   </browser>
</browsers>

      

I sent the first request from Opera userAgent, it worked out and browserName

identified as "Opera", but then I sent a second request from the user ChromeAgent and browserName

which is still identified as "Opera". What am I doing wrong?

+3


source to share


1 answer


If you only need to define the browser for its own sake, you can't go wrong if the application identifies the Opera browser as Chrome.



Opera completely switched its rendering engine with WebKit last year, so it doesn't really matter the weather you serve for content in Chrome or Opera or any other browser running WebKit.

0


source







All Articles