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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With