Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect new Microsoft browser "Edge" in asp.net

In asp.net, using this construct, how might I detect the new Microsoft "Edge" browser?

    Dim wrkBrowser As String = ""
    Dim wrkBrowserType As String = HttpContext.Current.Request.Browser.Type
    If InStr(wrkBrowserType, "Chrome") <> 0 Then
        wrkBrowser = "Chrome"
    End If
    If InStr(wrkBrowserType, "MSIE") <> 0 Then
        wrkBrowser = "IE"
    End If
    If InStr(wrkBrowserType, "FireFox") <> 0 Then
        wrkBrowser = "FF"
    End If
like image 496
wayfarer Avatar asked Jul 04 '15 18:07

wayfarer


2 Answers

I know the answer is a little late but I searched all over the place and never found this and had to write it myself. The following code will allow the Request.Browser variables to return Edge and Edge Version instead of Chrome.

Adding the following snippet to a .browser file such as platform.browser in the App_Browsers folder will cause it to return Edge and the version.

<browser id="Edge" parentID="Chrome">
  <identification>
    <userAgent match="Edge/(?'version'(?'major'\d+)(?'minor'\.\d+))" />
  </identification>
  <capabilities>
    <capability name="browser" value="Edge" />
    <capability name="version" value="${version}" />
    <capability name="majorversion" value="${major}" />
    <capability name="minorversion" value="${minor}" />
  </capabilities>
</browser>
like image 104
John Avatar answered Sep 28 '22 07:09

John


As Joey mentioned, the User Agent string is what you want to look at. The properties of Request.Browser don't contain anything specific to Edge, but you can get the user agent string with HttpContext.Current.Request.UserAgent and use .IndexOf("Edge") to search it.

like image 30
Travis Carney Avatar answered Sep 28 '22 06:09

Travis Carney