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
Response.Write(Request.UserAgent);



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

Mobile
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
https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx


Note: Very important, Microsoft Edge – don’t do browser detection
Small note on MSDN must read.
http://blogs.msdn.com/b/drougge/archive/2015/08/19/microsoft-edge-don-t-do-browser-detection.aspx