Tuesday 26 January 2016

How to detect the Edge browser in asp.net C#?

We can do this by using HttpBrowserCapabilities where we have browaser type and user agent to track browser.

A. Using Browser Type
HttpBrowserCapabilities brObject = Request.Browser;

// Display the type and version.
Response.Write("Browser Type: "+ brObject.Type);
Response.Write("<p>"+"Browser Version: "+ brObject.Version);

B. Using User Agent

User agent for Edge browser are:
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

Mozilla/5.0 (Windows Phone 10.0; Android <Android Version>; <Device Manufacturer>; <Device Model>) AppleWebKit/<WebKit Rev> (KHTML, like Gecko) Chrome/<Chrome Rev> Mobile Safari/<WebKit Rev> Edge/<EdgeHTML Rev>.<Windows Build>

More user agent for edge browser on MSDN

Note: Very important, Microsoft Edge – don’t do browser detection
Small note on MSDN must read.