Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App_Browsers definition file for Edge

I'm trying to write a browser definition file for Edge in Asp.Net to avoid having it identified as "Chrome 46".

I've created the following Edge.browser file in the App_Browsers folder:

<browsers>
  <!--Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586-->      
  <browser id="Edge" parentID="Chrome">
    <identification>
      <userAgent match="Edge" />
    </identification>
    <capture>
      <userAgent match="Edge/(?'version'(?'major'\d+)(\.(?'minor'\d+)?))" />
    </capture>
    <capabilities>
      <capability name="browser" value="Edge" />
      <capability name="version" value="${version}" />
      <capability name="majorVersion" value="${major}" />
      <capability name="minorVersion" value="${minor}" />
    </capabilities>
  </browser>
</browsers>

This matches Edge very well, but then if make another request to the website with Chrome, the browser also gets matched as Edge :S

What am I doing wrong?

like image 351
Gyum Fox Avatar asked Jul 28 '16 15:07

Gyum Fox


1 Answers

Try to change your definition to:

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

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

  </browser>
</browsers>

Dont put the regex in <capture>-Tag but in <identification>

EDIT

Since the userAgentCacheKeyLength is limited to 64 by default, the trailing chars get cut off and that leads to your described behavior. Luckyly there is a workaround.

Add these lines in your web.config

<system.web>
    <browserCaps userAgentCacheKeyLength="256" />
</system.web>

Now every Chrome-Based browser should reveal correctly since its full key is recognised

like image 154
lokusking Avatar answered Sep 27 '22 22:09

lokusking